Question: Write a Python 3 program (hw3.py)to demonstrate the use of iterators described in Chapter 6. Write a generator named powers that takes a single argument,

Write a Python 3 program (hw3.py)to demonstrate the use of iterators described in Chapter 6. Write a generator named powers that takes a single argument, a positive integer n, and generates triples (i, i2, 3) from i-1 to n. Use that generator to create a list of triples for the frst 5 positive integers. Print the created list. Then get the iterator for the created list and use it in a while loop (i.e., use (next) to print the middle number from the triples in the list (do not use for loop). Make sure to handle any exception. The output must be: [1, 1, 1), (2,4, 8), 3, 9, 27), (4, 16, 64), (5, 25, 125)1 4 16 25 Make sure to comment your code and to explain how it works. (20 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
