[Tutor] invalid syntax (reply)
Alan Gauld
alan.gauld at btinternet.com
Fri Sep 25 01:13:46 CEST 2009
"Corey Richardson" <kb1pkl at aim.com> wrote
> Closing the parenthesis helped that one, but my else statement is not
> working...heres the code chunk...
> if wellness != "Good":
> elif wellness != "Well":
> elif wellness != "Fine":
> print "Oh, I'm sorry you are not feeling well. I guessed
> correct, right?"
> else print "Great!"
As has been pointed out you need to use a boolean expression
(a combination of tsts using and / or ) to get the result you need.
In fact if you describe what you really want in English you will find
it forms a boolean expression.
You want it to print one message if the user types Good or Well or Fine
else print another message. Now translate that directly to code...
> candyNumber = raw_input("How many candies do you want? :")
> fatness = raw_input("How many candies do you want to eat? :")
> if fatness > candyNumber:
> print "HA! Nice try, but no. You don't have that many candies"
> else print "HA! You ate the candy! Suckerrrrr. You are now",
Python cares abourt indentation level.
align the else with the if that it matches.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list