+ 1

Turn loop into recursive function

Can anyone give an me some direction on how to turn a for or while loop into a recursive function in python? Let's say I have a very simple function that takes one argument n which is the number of times I want to repeat the same calculation x+=1 and the function calculates it and returns and prints the outcome. In a loop I would ask the code to repeat in a range of 1 to n # for x in range(1,n): # I want to turn this into a recursive function that repeats the function that many times. let's say this is the loop I want to turn into a function n = int(input()) x = 0 for x in range(0, n): x += 1 print(x)

26th Dec 2020, 11:47 AM
Manuel MĂŒller
Manuel MĂŒller - avatar
2 Answers
0
thank you!
26th Dec 2020, 12:24 PM
Manuel MĂŒller
Manuel MĂŒller - avatar