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]
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 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. ----------------------------------------------------------------------------------------------------------------------------------------------------------...
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...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list...
python 3 For this exercise you are to implement the function poly_iter in the array-backed list class, which, when called with positive integer parameters a, b, c, returns an iterator over the values in the underlying list at indexes a*i2+b*i+c, for i=0, 1, 2, ... E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code: for x in lst.poly_iter(2, 3, 4): print(x) will produce the output: 4 9 18 31...
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...
PYTHON Ask the user for a value N (0 ≤ N < 10) Create a 2-D...
PYTHON Ask the user for a value N (0 ≤ N < 10) Create a 2-D list in an N X N structure with integers 1-(N*N) Print the list created Reverse the list such that (1) each list in the 2D list is reversed and (2) the order of each list in the outer list is reversed (see example) Print the reversed list Example Execution What size 2D list would you like to create? N> 3 The original list is:...