#Guess my number
#The computer picks a random number between 1 and 100
#the player tries to guess it an dhte computer lets
#the player know if the guess is too hight, 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 "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 = 1
#guessing loop
while (guess != the_number):
if (guess > the_number)
print "Lower..."
else:
print "Higher..."
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, "tries!\n"
#this is the end
#this is a copy of the script run on python
>>> #Guess my number
...
>>> #The computer picks a random number between 1 and 100
... #the player tries to guess it an dhte computer lets
... #the player know if the guess is too hight, too low
... #or right on the money
...
>>> import random
>>>
>>> print "\tWelcome to 'Guess My Number'!"
Welcome to 'Guess My Number'!
>>> print "\nI'm thinking of a number between 1 and 100."
I'm thinking of a number between 1 and 100.
>>> print "Try to guess it in as few attempts as possible. \n"
Try to guess it in as few attempts as possible.
>>>
>>> #set the initial values
...
>>> the_number = random.randrange(100) + 1
>>> guess = int(raw_input("Take a guess: "))
Take a guess: tries = 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'tries = 1'
>>>
>>> #guessing loop
...
>>> while (guess != the_number):
... if (guess > the_number)
File "<stdin>", line 2
if (guess > the_number)
^
SyntaxError: invalid syntax
>>> print "Lower..."
File "<stdin>", line 1
print "Lower..."
^
IndentationError: unexpected indent
>>> else:
File "<stdin>", line 1
else:
^
IndentationError: unexpected indent
>>> print "Higher..."
File "<stdin>", line 1
print "Higher..."
^
IndentationError: unexpected indent
>>>
>>> guess = int(raw_input("Take a guess: "))
Take a guess: tries += 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'tries += 1'
>>>
>>> print "You guessed it! the number was", the_number
You guessed it! the number was 18
>>> print "And it only took you", tries, "tries!\n"
And it only took you
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'tries' is not defined
Running Ubuntu Gutsy gibbons, and emacs
I have checked the code carefully but can't get past the first traceback error.
Thanks for any help.