Python Programming/Decision Control/Solutions
From Wikibooks, the open-content textbooks collection
Write a program that has a user guess your name, but they only get 3 chances to do so until the program quits.
name = raw_input("What's my name? ") answer = "Jack" attempt = 0 if name == answer: print("That's correct!") else: while name != answer and attempt < 2: attempt = attempt + 1 name = raw_input("That's incorrect. Please try again: ") if name == answer: print("That's correct!") elif attempt == 2: print("You've exceeded your number of attempts.")