I'm working with functions and arguments and even with a simply code when function is called inside I'm getting error like: line 7, in question if ask == 'yes': RecursionError: maximum recursion depth exceeded in comparison
If I type in: Yes in answer, yes it works fine but when I type in: no and function is called belowe else statement I get error: line 5, in question if ask == 'yes': RecursionError: maximum recursion depth exceeded in comparison
I'm doing something wrong? BTW I googled the problem and doesn't solve problem sys.setrecursionlimit(5000) and still getting error:
ask = input("Are you OK?:").lower()
asked = ask
def question(n):
if ask == 'yes':
return n
else:
question(n)
print (question(asked))
I tried another way:
def question():
ask = input("Are you OK?:").lower()
if ask != 'yes':
question()
else:
return ask
print(question())
But in this code it works only if I answer 'yes' straight away, if I answer first time 'no' it ask again as expected and when second time I answer 'yes' it returns and prints: NONE.
ask != 'yes'then the function will just call itself indefinitely (or until max recursion depth is exceeded).