On 08/12/14 23:06, Awais Idris wrote:
The problem is when i enter my first choice it accepts it fine and well.
When it says would you like a second item, andi say yes it listd the
options and says have a good day and the program cuts off. In wondering if
this is a problem with the statements?
As Danny pointed out both Steven and I suggested a better way to test.
In case you missed it here is Steven's response:
################################
Actually it sees it as:
if ((FirstChoice == 'Coke') or 'Pepsi' or 'Water'):
which will always evaluate as True.
*Technically* it will evaluate as either True or 'Pepsi', which is a
truthy value, so the if block will always run.
What we actually want is one of these:
# The long way
if (FirstChoice == 'Coke') or (FirstChoice == 'Pepsi') or (FirstChoice
== 'Water'):
# The short way
if FirstChoice in ('Coke', 'Pepsi', 'Water'):
###################################
And since you already have the drinks in a set you can
shorten the last line even further to:
if FirstChoice in drinks:
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor