[Tutor] Beginners question

gary littwin gary.littwin at gmail.com
Thu Oct 8 14:47:50 CEST 2009


Hi all -

Just started on "Python Programming for Absolute Beginners" and I've got a
question:

The program called 'Guess my Number' goes like this:
# 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 15."
print "Try to guess it in as few attempts as possible.\n"

import random


# set the initial values
the_number = random.randrange(15) + 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"

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

So here's the question - the original code has parentheses around the lines
of code with *(guess !=the_number)* and *(guess* *> the_number)* .  I tried
to run the program without the parentheses and it runs just fine.  So what
are the parentheses for??

Thanks a lot for your time -

             Gary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091008/8d12f64b/attachment-0001.htm>


More information about the Tutor mailing list