[Tutor] command error

Shurui Liu (Aaron Liu) shurui91 at gmail.com
Tue Feb 16 21:32:44 CET 2010


Here is a program I wrote, I don't know why I cannot exit when I tried 10
times? Hope somebody can help me. Thank you!




# Guess My Number
#
# The computer picks a random number between 1 and 100
# The player tries to guess it and the computer lets
# the player know if the guess is too high, too low
# or right on the money

import random

print ("\tWelcome to 'Guess My Number'!")
print ("\nI'm thinking of a number between 1 and 100.")
print ("You have only 10 times to guess the number. Try to guess it in as
few attempts as possible.\n")

# set the initial values
the_number = random.randrange(100) + 1
guess = int(raw_input("Take a guess: "))
tries = 9

# guessing loop
while (guess != the_number):
    if (guess > the_number):
        print ("Lower...")
        print ("You were wrong, try again", tries, "times left.\n")
    else:
        print ("Higher...")
        print ("You were wrong, try again", tries, "times left.\n")

    guess = int(raw_input("Take a guess: "))
    tries -= 1

print ("You guessed it!  The number was"), the_number
print ("And it only took you", "tries times", "tries !\n")

if ("tries = 0"):
    print "You have tried 10 times, game over."
    raw_input("\n\nPress the enter key to exit.")

raw_input("\n\nPress the enter key to exit.")

-- 
Shurui Liu (Aaron Liu)
Computer Science & Engineering Technology
University of Toledo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100216/a39c69da/attachment.htm>


More information about the Tutor mailing list