Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.
This problem can be solved by taking a variable that counts from 1 to n.
We print the variable twice, every time the function is called and then recall the fuction after incrementin the value.
NOTE : Take care of the indentation in the code using the screenshot.
CODE :
def recur(x,i):
i=i+1
print(i, end = '')
print(i, end = '')
if i<x:
recur(x,i)
x = int(input("Enter an integer : "))
i = 0
recur(x,i)
OUTPUT :
Enter an integer : 10
1122334455667788991010
Get Answers For Free
Most questions answered within 1 hours.