(I'm a beginner in Python, just so you know)
What I'm trying to do: I want to keep count of how many times a user choose a wrong option and if it exceeds a number of times, he fails.
My approach was to store the count in a variable within a function and check with if/else statement if the number of times is exceeded.
Part of the code:
choice = int(input("> "))
if choice == 1:
print("This is the wrong hall.")
increment()
elif choice == 2:
print("This is the wrong hall.")
increment()
elif choice == 3:
hall_passage()
else:
end("You failed")
COUNT = 0
def increment():
global COUNT
COUNT += 1
increment()
print(COUNT)
The increment part is from this thread and read using global scope is not a good practice.
The part I don't really understand is how you store count in a variable and it remembers the last value every time the function runs.
What is the best way to do this?