New to programming question

Ben benmarkwell at gmail.com
Thu Mar 31 23:03:00 EST 2005


This is an exercise from the Non-programmers tutorial for Python
by Josh Cogliati.

The exercise is:

Write a program that has a user guess your name, but they only get 3
chances to do so until the program quits.

Here is my script:

--------------------------

count = 0
name = raw_input("Guess my name. ")

while name != 'Ben' and count < 3:
    count = count + 1

    if name != 'Ben' and count < 3:
        name = raw_input('Guess again. ')
    elif name == 'Ben' and count < 3:
        print "You're right!"
    else:
        print 'No more tries.'

----------------------------------

Everything works except the line:  print "You're right!"

Could someone tell me what is wrong and give me a better alternative to
what I came up with.  

Thank you 

Ben




More information about the Python-list mailing list