Python: Write a recursive function that takes in a number as a parameter and calculates the square of the number up to and including the value of the parameter.
def square(x):
"""This is a recursive function
that calculates the square of the number up to
and including the value of the parameter"""
print (x * x)
if x == 1:
return
else:
return square(x-1)
num = int(input("Enter a number: "))
square(num)
Get Answers For Free
Most questions answered within 1 hours.