Hi,
I am learning python and I am trying to write a simple "guess the number"
game. I wrote the program in the IDLE, and I set the variable tries=1 to keep
up
with the number of tries it takes to guess the number, but when I try to run
the
program it gives the error message "improper syntax" and highlights the word
tries. So, I assigned the variable tries the value 1 in the python shell
window
and it works fine there. Can you tell me why it won't work in the program? A
copy of my code is below for clarification.
#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 correct
import random
print('Welcome to "Guess My Number"!')
print('\nI\'m thinking of a number between 1 and 100.')
print('Try and guess the number in as few turns as possible.')
#set initial values
num = random.randint(1,100)
guess = int(input('Take a guess: ')
tries = 1
while guess != num:
if guess > num:
print('Too high. Guess lower.')
else:
print('Too low. Guess higher.')
guess=input('Take another guess: ')
tries += 1
print('You guessed it. The number was',num)
print('Congratulations, You guessed the correct answer.'
print('It only took you',tries,'tries.')
input('\n\nPress enter to exit.')
I highlighted the problem in red.
Thanks for any help.
Kyle
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor