Question

In: Computer Science

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]

Solutions

Expert Solution

powerof5.py

def powersOf5( n ):
   result = [1]
  
   i = 1
   init = 1
  
   while n>1:
       result.append(init*5)  
       i = i+1
       n = n-1
       init = init*5
      
   print(result)

powersOf5(1)
powersOf5(2)
powersOf5(3)
powersOf5(6)
powersOf5(10)

Output :

[1]

[1, 5]  

[1, 5, 25]                                               

[1, 5, 25, 125, 625, 3125]                               

[1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125]


Related Solutions

In Python, Complete the longestWord() function to take a list as a parameter and return the...
In Python, Complete the longestWord() function to take a list as a parameter and return the length of the longest word in that list. Examples: longestWord(['Python', 'rocks']) returns 5 longestWord(['Casey', 'Riley', 'Jessie', 'Jackie', 'Jaime', 'Kerry', 'Jody']) returns 6 longestWord(['I', 'a', 'am', 'an', 'as', 'at', 'ax', 'the']) returns 3
In Python Complete the oddNumbers() functions to take an int (as a parameter). Return a list...
In Python Complete the oddNumbers() functions to take an int (as a parameter). Return a list of all of the odd numbers between 1 and one less than the parameter. Also, complete the evenNumbers() functions to take an int (as a parameter). Return a list of all of the even numbers between 2 and one less than the parameter.
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list. (please do on racket language)
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list.
Using Python 1. #Now, let's improve our steps() function to take one parameter #that represents the...
Using Python 1. #Now, let's improve our steps() function to take one parameter #that represents the number of 'steps' to print. It should #then return a string that, when printed, shows output like #the following: # #print(steps(3)) #111 #   222 #       333 # #print(steps(6)) #111 #   222 #       333 #           444 #               555 #                   666 # #Specifically, it should start with 1, and show three of each #number from...
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than...
Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7: 42 seconds #include <stdio.h> void PrintPopcornTime(int bagOunces) { } int main(void) { int userOunces; scanf("%d", &userOunces); PrintPopcornTime(userOunces); return 0; } 2. Write a function PrintShampooInstructions(), with int parameter numCycles, and void return...
a) Write a function drawShape() that accepts a parameter n, and: If n is odd, it...
a) Write a function drawShape() that accepts a parameter n, and: If n is odd, it constructs a pattern of a diamond of height n If n is even, it constructs an hourglass of length n b) What is the time complexity of the drawShape() function you created? C++ language with for loop
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie...
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie Germain prime that is greater or equal to n.
Write a python function average_sample_median(n,P), that return the average of 1000 samples of size n sampled...
Write a python function average_sample_median(n,P), that return the average of 1000 samples of size n sampled from the distribution P. * Sample run : print(average_sample_median(10,[0.2,0.1,0.15,0.15,0.2,0.2])) print(average_sample_median(10,[0.3,0.4,0.3])) print(average_sample_median(10,P=[0.99,0.01]) * Expected Output : 3.7855 2.004 1
complete in python The function sumEven should return the sum of only the even numbers contained...
complete in python The function sumEven should return the sum of only the even numbers contained in the list, lst. Example list_of_nums = [1, 5, 4, 8, 5, 3, 2] x = sum_evens(list_of_nums) print(x) #prints 14 Start your code with def evens(lst):
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT