Apr-03-2018, 03:35 AM
Recursive invocation is limited by depth.
Using infinite loop is more preferable in this case.
count = 0 def main(): global count count += 1 return count main()This code leads to
Output:
File "<stdin>", line 4, in main
File "<stdin>", line 4, in main
RuntimeError: maximum recursion depth exceeded
>>> count
999
So, the program can't produce too much queries (but this behavior (recursion depth) could be tweaked).Using infinite loop is more preferable in this case.
from random import randint it = randint(0, 101) def guess(): while True: x = int(input('Guess a number one through one hundred: ')) if x == it: print("You got it!") break elif x > it: print("too high") else: print("too low") guess()