(Please don't top-post. Place your remarks after whatever quoting you do from the previous message. And trim the parts that are no longer relevant)

On 09/30/2011 03:18 PM, ADRIAN KELLY wrote:
please guys
still stuck on this problem and i have been at it for hours so please if anyone 
can help.  it nearly works. am i looking at it from the wrong angle? i have 
tried everyone's suggestions but i am stuck still...
correct code would be nice.............
thanksadrian (new pythoner)

print("\tWelcome to 'Guess My Number'!")print("I'm thinking of a number between 1 and 
100.")print("Try to guess it in as few attempts as possible.\n")
# set the initial valuesage = 35guess = " "tries = 5
# guessing loopwhile guess!=age and tries>0:    tries=tries-1    guess = input("Take a guess: ")    if guess>  age and tries>0:        print 
"Lower...",tries,"left"    elif guess<  age and tries>0:        print "Higher...",tries,"left"    elif guess == age and 
tries>0:        print "Correct...well done!!"    else:        break        print "Out of attempts"
print "\n\nGood guess!!"
   input ("\n\nPress the enter key to exit.")

Please adjust your email program to text mode. Wordwrapping python source code doesn't work very well.

input() returns a character string. If you want an integer, you need to use int() function. Currently you're comparing an integer 35 to a string like "4". That comparison is effectively indeterminate. (there are rules for it, but they vary by both version and implementation, so it's better to always make sure you have the same type on both sides of the comparison operator.

--

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to