[prog] why doesn't this program work? (python)

Jacinta Richardson jarich at perltraining.com.au
Thu Dec 19 16:06:22 EST 2002


It did come with indentation... perhaps it got stripped by some mailers?

Anyway I'm wondering whether the problem might be here:

guess = input("Guess a number: ")

In Perl at least, if I were to enter 
3
that would be interpreted as "3\n" which would never be the same as "3".
Do you have to do something special to remove the newline?  If not how
do you tell python that you intended to enter a newline?

I haven't done much with Python, so I'm quite possibly mistaken.

	Jacinta

> #Plays the higher or lower game
> #uses the time, seconds as the random no.
> #the aim is to have a random no. assigned and have someone guess it....with
> #them getting hints of higher and lower
> #prob. is it doesn't exit the while loop when the correct no. is guessed....
> from time import strftime
> number = strftime("%S")
> print number
> guess = 0
> 
> while guess != number:
> 	guess = input("Guess a number: ")
> 	if guess < number:
> 		print "Too low"
> 	elif guess > number:
> 		print "Too high"
> 
> print "Just right :)"


Good luck.

	Jacinta

--
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson	    |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +613 9354 6001 	    |  
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
(il),-''  (li),'  ((!.-'              |   www.perltraining.com.au   |




More information about the Programming mailing list