On Tue, Sep 29, 2009 at 11:40 PM, Corey Richardson <kb1...@aim.com> wrote:

> I got suggested to use this format for my code, as it was shorter and
> prettier. But It dun work!
> if wellness != ["Well","Fine","Good", "OK", "ok", "Ok", "Great", "Awesome",
> "Epic"]:
>   print "Oh, I'm sorry you are not feeling well."
>   areYouOk = raw_input("I guessed correct, right?")
>   if areYouOk != ["yes", "yep", "yup", "yea"]:
>       print "Oh, thats to bad. Things will be better"
>   else  :
>       print "Oh, I'm glad your ok then!"
> It just prints the "Oh, I'm sorry you are not feeling well.", and then when
> you reply, it says "Oh, thats to bad. Things will be better"/
> Ahhh! Why does it be do this? And there is no error, btw.
>
There is no SYNTAX error.  That does not mean there is no semantic error.
A syntax error means your notation is wrong.  A semantic error means you are
not asking the computer what you think you are asking it.
In this case you are saying "is their input equal to this list with many
elements?" and the answer is always going to be No because a string won't be
equal to a list unless both are empty.
What you want to be asking is "is this string IN this list somewhere?"
I.E.
if wellness.strip().lower() in ["well", "fine", "good", "whatever"]:
note if you strip & lowercase the list it is far more likely you'll match
your input.
In your case if I typed in "wEll " it would not match "well".


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

Reply via email to