PYTHON: Write a 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. The function must perform the process recursively.
Code:
def square(n): # defining a recursive function
if n==0: # defining exit case
return 1
else:
square(n-1) # calling the function recursively
print(n*n) # printing the values
# driver code
n = int(input("Enter the number: ")) # taking input
square(n) # calling the function
Output:
Get Answers For Free
Most questions answered within 1 hours.