(In Python) Create an example for a generation expression that will compute the cute of all of the odd numbers between 1 and 100, show how you would use this generator.
Question: To compute the cube of all the odd numbers between 1 and 100, using generator concept.
Answer:
Please find below the copy of code, Screenshot of code and
Output.
Thanks.
def cubeof():
c=0
for i in range(1,101):
if i%2!=0:
c=c+i**3
else:
pass
yield c,
for j in cubeof():
print j
Output of the code
(In Python) Create an example for a generation expression that will compute the cute of all...
In python,Using list comprehension create an expression that sums up all the factors of an positive integer number. For example, if the number is 6, then the output should be 12 (i.e., 1+2+3+6 =12). Your answer should be only one line of code.
In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...
Python Help Create a program that outputs a table from 1 to 5 using what you've learned about "for" loops. Your program will print the number and indicate if the number is odd or even. If it is not odd you will multiply 2 numbers with it: number 1 and number 2. Your program must do the multiplication for only even numbers in the table. The output of your program should look like the figure below. Hint: Create a program...
Using Python: Exercise 2.5: Use a random number generator in Python (you can try numpy.random.choice, you will need to give it the two element array [-1,1]) to create several random walks, i.e. a lists of numbers where the Nth entry is the position of the robot after N steps with 100 total steps of length 1 and plot the position vs. step number. From looking at the random walks, discuss in words how the robot can move away from its...
Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...
Write a Python program that calculates the product of all odd numbers between 1 and 20 (1x3x5x7x9x11x13x15x17x19), using the for loop and the range function.
python Create an empty list of size 100 × 200 with all zeroes. How do you access the 4th row and 2nd column of a 2D list called Write a function called printList that takes as a parameter a 2D list and prints it to screen in row/column format. Create a multiplication table of size 10 × 10 that has all the products from 1 times 1 all the way up to 10 times 10. Create a 2D list (matrix)...
Python programming: Write a while loop that prints a. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81. b. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90 c. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16...
In python, how do you create an array of unknown dimensional
size?
I want to create an array of unknown dimensional size based on a
number I recieve. To elaborate, let's say n = 2, it will output a
3D array {true, true, true}. If n = 3, then its output will be a 4D
array {true, true, true, true}. Whatever the n value is, the return
value will be an array of n + 1 dimensional size. How would...
Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120