Question

# Python Given the list values = [], write code that fills the list with each...

# Python

Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary

  1. 1 2 3 4 5 6 7 8 9 10
  2. 0 2 4 6 8 10 12 14 16 18 20
  3. 1 4 9 16 25 36 49 64 81 100
  4. 0 0 0 0 0 0 0 0 0 0
  5. 1 4 9 16 9 7 4 9 11
  6. 0 1 0 1 0 1 0 1 0 1
  7. 0 1 2 3 4 0 1 2 3 4

Homework Answers

Answer #1
values=[]

#Note: range(start,end,increment)
# start is included and end is not included 
#increment by default is 1
#E.g: range(1,11,1) means a sequence 1,2,3,4,5,6,7,8,9,10

#List comprehension
#l=[i for i in range(1,11)] in this i is added to list for each i in range(1,11)

# For 1 2 3 4 5 6 7 8 9 10
# This is 1-10 in sequence, So using list comprehension we get it
values=[i for i in range(1,11)]
print("a:",values)

# For 0 2 4 6 8 10 12 14 16 18 20
# This even number sequence, So using list comprehension we get it
values=[i for i in range(0,22,2)]
print("b:",values)

# For 1 4 9 16 25 36 49 64 81 100
# This Square of number sequence, So using list comprehension we get it
values=[i*i for i in range(1,11)]
print("c:",values)

# For 0 0 0 0 0 0 0 0 0 0
# This is [0] 10 times. So if we multiple a list by nummber it gets repeated
# In this case we multiple by 10.
values=[0]*10
print("d:",values)

# For 1 4 9 16 9 7 4 9 11
# This is a random sequence. So we have to write each element 
# separated by ","
values=[1, 4, 9, 16, 9, 7, 4, 9, 11]
print("e:",values)

# For 0 1 0 1 0 1 0 1 0 1
# This is [0, 1] 5 times. So we multiple by 5.
values=[0, 1]*5
print("f:",values)

# For 0 1 2 3 4 0 1 2 3 4
# This is [0, 1, 2, 3, 4] 2 times. So we multiple by 2.
values=[0, 1, 2, 3, 4]*2
print("g:",values)

Output Screenshot:

Code Screenshots: (For better understanding of indentation)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code.
Python Question: Write a function which returns the sum of squares of the integers 1 to...
Python Question: Write a function which returns the sum of squares of the integers 1 to n. For example, the sum of the squares from 1 to 4 is 1 + 4 + 9 + 16, or 30. You may choose what should be returned if n == 0 You may not use the built-in Python sum function. The Solution Must be recursive >>> sum_of_squares(1) 1 >>> sum_of_squares(4) 30 >>> sum_of_squares(8) # 64 + 49 + 36 + ... +...
write a python program that include a function named activity_selection() and take in two arguments, first...
write a python program that include a function named activity_selection() and take in two arguments, first one would be the number of tasks and the second argument would be a list of activities. Each activity would have an activity number, start time and finish time. Example activity_selection input and output: activity_selection (11, [[1, 1, 4 ], [2, 3, 5], [3, 0, 6], [4, 5, 7], [5, 3, 9], [6, 5, 9],[7, 6, 10], [ 8, 8, 11], [ 9, 8,...
Write a Python expression that uses the list even_numbers below and evaluates to the list [4]....
Write a Python expression that uses the list even_numbers below and evaluates to the list [4]. or produces the list to [4] even_numbers = [0, 2, 4, 6, 8, 10, 12]
Python The function cube should receive a list as a parameter and return a new list...
Python The function cube should receive a list as a parameter and return a new list with each number taken in cubic (raised to three). Write the necessary code for the function, as well as an example which uses the function to calculate and print the cubes for the numbers 5, 8 and 9
PLEASE CODE EVERYTHING IN C++ Quick Thinking: Arrays Objective: Test your knowledge in providing efficient solutions...
PLEASE CODE EVERYTHING IN C++ Quick Thinking: Arrays Objective: Test your knowledge in providing efficient solutions for operations on arrays. What you can use only: Loops These variables only const int SIZE = 4; int variable = 0, master array [SIZE][SIZE]; double average = 0.0, parallel array [SIZE]; One conditional statement per problem if needed Note: the conditional statement cannot contain an “else” or “else if’ Provide solutions to the following problem. Absolutely no hard coding can be used. ----------------------------------------------------------------------------------------------------------------------------------------------------------...
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14...
A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] In MATLAB. Use a fully vectorized code (ie. no loops) to determine when the numbers have increased to at least 15 in the above array. Report answer to command window.
This dataset contains consumer responses indicating the number of times they had to send their product...
This dataset contains consumer responses indicating the number of times they had to send their product for repair and their satisfaction with the repair process. Create a graph which can be used to visually demonstrate the relationship between the two columns of data. Ensure that the chart is professional with appropriate titles, axis labels, etc. Note any observations you see in your visualization (type these as sentences directly into an Excel cell(s)). Sample Satisfaction Rating Repair Requests 1 63% 13...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT