i have looked for a solution to this but can't find one. i want to do a recursion but the function cannot have a return statement. here is the program:
n = input("Input a positive integer: ")
text = open("Nummbers.txt", "w")
text.write("Number inputed: " + str(n))
tree(n)
def tree(n):
if(n>0):
tree(n-1)
print(n)
text.write(str(n))
tree(n-1)
when i run it it gives me a 'tree not defined error'. tree must be written as above. how do i get this to work properly all recursion tutorials that i have seen have set it up as such, i am using python 2.7
tree(n)withres = tree(n); print(res)to see what I mean. Why can't you have an explicit return statement?