Objective:
If the user types "right" the first two times, the smiley becomes sad as it can't get out of the forest.
If the user types "right" 3rd, 4th, 5th time an so on, the smiley becomes frustrated, chops some trees, makes a table and flips it over.
If the user types anything else, a message showing "Invalid input" is shown to the user and asked to give input again.
If the user types "left", the smiley gets out of the forest and the program terminates.
Python code:
n = input("You are in the Lost Forest\n****************\n****************\n :)\n****************\n****************\nGo left or right? ")
i = 1
while (n.lower() == "right"):
if i < 3:
n = input("You are in the Lost Forest\n****************\n****************\n :(\n****************\n****************\nGo left or right? ")
elif i >= 3:
n = input("You are in the Lost Forest\n****************\n****** ***\n (╯°□°)╯︵ ┻━┻\n****************\n****************\nGo left or right? ")
i = i + 1
while (n.lower() != "right") and (n.lower() != "left"):
n = input("Invalid Input\nYou are in the Lost Forest\n****************\n****************\n :(\n****************\n****************\nGo left or right? ")
while (n.lower() == "left"):
print("\nYou got out of the Lost Forest!\n\o/")
break
Bug:
If the user types anything other than "right" or "left" for the first two times and then types "right", the program immediately terminates without giving chance to type "left".
How should I edit my code?
while(playing==True):and before thebreakon your last loop, setplaying=Falseif - elseformat, but still unsuccessful.while Trueloop as @Tacratis suggestswhile True? I am not familiar with it.