: Hi, I'm quite a newbie in programming, so this would seem a little lame quesion but I need your help!
: So I started learning Python, but I encountered a problem I can't cope with. My task is to "Write a program that has a user guess your name, but they only get 3 chances to do so until the program quits."(hey dont start laughing! :)
: I've written something but I can't make him to work properly:
:
: my_name = "Squirrel"
: a = 0
: guess = raw_input ("What's my name?")
:
: while a != 3:
: if guess == my_name:
: print "That's it!"
: else:
: print "Try again."
: a = a + 1
:
: I've tried several ways to do that task but I've always ended up in looping. Could somebody please help me telling what am I doing wrong?
Here's one way to do it:
my_name = "Squirrel"
a = 0
while a != 3:
guess = raw_input("Guess my name: ")
if guess == my_name:
print "That's it!"
break
else:
print "That's not it!"
a = a + 1
else:
print "Sorry!"
Make sure you get the indentation correct! In Python it matters.