I'm new to learning Python and haven't programmed much since I left school at the beginning of the summer. Im trying to write a program that will give a user 3 attempts to guess my name:
As it is, if the user inputs an incorrect name instead of displaying the error message and re asking for the name, it just gets trapped and repeatedly displays the error message until the program is stopped. Now in something I'm familiar with like VB I'd know how to do this, but with python I don't know how to loop the whole asking for input process until count = 3. This is an exercise from the wikibook on Python btw. How do i structure the program to do this? Thanks.
Code:
count = 0
name = raw_input("Try and guess my name: ")
if name != "Andrew":
count + 1
else:
print "Well done, thats right!"
while name != "Andrew" and count < 3:
print "Sorry, try again!"
As it is, if the user inputs an incorrect name instead of displaying the error message and re asking for the name, it just gets trapped and repeatedly displays the error message until the program is stopped. Now in something I'm familiar with like VB I'd know how to do this, but with python I don't know how to loop the whole asking for input process until count = 3. This is an exercise from the wikibook on Python btw. How do i structure the program to do this? Thanks.