[Tutor] Not workin!

Luke Paireepinart rabidpoobear at gmail.com
Tue Sep 29 23:44:59 CEST 2009


On Tue, Sep 29, 2009 at 11:40 PM, Corey Richardson <kb1pkl at 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 at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090929/d661624a/attachment.htm>


More information about the Tutor mailing list