[Tutor] guess age programme (please help)

Christian Witts cwitts at compuscan.co.za
Fri Sep 30 14:31:52 CEST 2011


On 2011/09/30 02:04 PM, ADRIAN KELLY wrote:
> Hi all,
> can anyone help me with the attached programme. it is fairly basic 
> (like me)  i want it to ask the user to guess the age and countdown 
> when making incorrect guesses.  it doesn't seem to count the first 
> attempt (run it and see please).  i also want to know how to go about 
> setting a condition so
> that when the guesses = 0, the programme closes or stops etc.
> any advice would be very grateful (particularly the correct code) i am 
> learning if's and loops so please keep explanations as
> simple as possible.
>
> i really appreciate everyones help
>
> adrian
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Your program does count the first guess, but you print out the remaining 
number of tries before you subtract the attempt from your counter so if 
you move your `tries=tries-1` up before your if statements it will 
reflect the correct number of attempts left to the user.

I would suggest changing your while loop to read `while tries > 0:` so 
it exits when you've exhausted your attempts.  You also do not test for 
equality of your age and the guess in your if statements so if the user 
guesses the correct age it will tell them that the number is higher. And 
if the user guesses the correct number you should `break` from the loop 
else it will carry on going till the number of attempts have been exhausted.


-- 

Christian Witts
Python Developer

//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110930/0c45fbc4/attachment.html>


More information about the Tutor mailing list