Okay, I know you can have a program keep running while a certain condition is true using the while statement. However, is it incorrect or bad practice to just recall the function in the else condition like below?
def ask():
me = input("What is your name? ")
if me == "Tom":
print("Hi, Tom!")
else:
print ("Who are you?")
ask()
It just seems like an easier, shorthand version of the ‘while statement’ but I haven’t really seen a program executed like this in the Python tutorials.
To be totally honest they both “work” it just depends on your user case. Granted you are more likely to hit recursion depth compared to something going wrong with while they both achieve similar results. Really its more simple and in my opinion slightly more pythonic (in this specific case) to use a while loop. (why make it more complicated?)