Question

In Python Complete the function powersOf5(). Have the function take a parameter n and return a...

In Python Complete the function powersOf5(). Have the function take a parameter n and return a list of the first n powers of 5. One way to calculate powers of 5 is by starting with 1 and then multiplying the previous number by 5.

Examples:

powersOf5( 1 ) returns [1]

powersOf5( 2 ) returns [1, 5]

powersOf5( 3 ) returns [1, 5, 25]

powersOf5( 6 ) returns [1, 5, 25, 125, 625, 3125]

powersOf5( 10 ) returns [1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

output:

def powersOf5(n): #function
powers_of_n_list = [1] #initialize list with one element with value 1, thus index at element 0 is 1
for i in range(1,n): #loop through 1 to n-1
powers_of_n_list.insert(i,powers_of_n_list[i-1]*5) #insert element which is obtained by multiplying 5 with element at previous index at index i of list , thus element at index 1 = element at index 0 * 5 = 1*5 = 5, element at index 2 = element at index 1*5 = 5*5 = 25 and so on..
return powers_of_n_list #return list

print("powersOf5(1): ", powersOf5(1))
print("powersOf5(2): ", powersOf5(2))
print("powersOf5(3): ", powersOf5(3))
print("powersOf5(6): ", powersOf5(6))
print("powersOf5(10): ", powersOf5(10))

Add a comment
Know the answer?
Add Answer to:
In Python Complete the function powersOf5(). Have the function take a parameter n and return a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT