Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a.Name your file recursive_power.py . b.Ask for the user to enter a base number,

ID: 3839771 • Letter: A

Question

a.Name your file recursive_power.py.

b.Ask for the user to enter a base number, and an exponent (the power to raise the base to). Ensure that the exponent is a non-negative integer. This means 0 and 1 are valid exponents.

c.Above is an example of what your program interaction might look like. It does not have to be exactly like this, as long as it works correctly. This shows the program run three times, with the numbers 3333 and 0, 555 and 1, and 4 and 6.

d.Be sure to include the four lines of documentation at the top of each program, and a short comment above every line or small section of Python code.

Can you use and online compiler link such that i can get code in better format

Explanation / Answer

# The Below program is used to output which is power of base number by exponent.
#To use power function we are importing msth library
#Exponent and base number providing by the user.
#Then check whether exponent is negative or not.
#If exponent is negative the display error.
#If exponent is not negative then display result .

import math # This will import math module   
firstNum = input('Enter the Base number') #Getting Base from user
exponent = input('Enter the exponent: ') #Getting exponent from user

if exponent < 0: #Checking exponent is not in negative
print "Exponent can't be zero" #if exponent is negative displaying error
  
else:
print " Result is : ", math.pow(firstNum, exponent) #if exponent is not negative displaying the result

Output:

sh-4.3$ python recursive_power.py                                                                                                                                               

Enter the Base number333                                                                                                                                             

Enter the exponent: 0                                                                                                                                                

Result is :  1.0                                                                                                                                                    

sh-4.3$ python recursive_power.py                                                                                                                                               

Enter the Base number555                                                                                                                                             

Enter the exponent: 1                                                                                                                                                

Result is :  555.0                                                                                                                                                  

sh-4.3$ python recursive_power.py                                                                                                                                               

Enter the Base number4                                                                                                                                               

Enter the exponent: 6                                                                                                                                                

Result is :  4096.0