[Tutor] Not workin!

Brett Wilkins lupin at orcon.net.nz
Wed Sep 30 09:12:51 CEST 2009


On 30/09/2009, at 10:44 AM, Luke Paireepinart wrote:

>
>
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Hey Corey,

I do believe I recommended this way of doing a conditional, and Rich/ 
Luke are right, you need to be testing whether or not the string is / 
in/ the list, ie:
if wellness not in list_of_wellness_strings:
	#do stuff

Luke's use of lower and strip are also good ideas :)

Cheers
--Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090930/9f1caa8c/attachment.htm>


More information about the Tutor mailing list