[Tutor] Conditional Statement without if statement?
Alan Gauld
alan.gauld at yahoo.co.uk
Wed Feb 9 05:14:34 EST 2022
On 09/02/2022 01:17, Barrett Ferguson wrote:
> Alright guys, I went to tutoring hours and got some help to figure out the answer. Il’ll re-enter the question for reference:
> Write code that sets the value of a variable named delicious to True if jellybeans is greater than 20, or licorice is greater than 30, or their sum is greater than 40. Otherwise, set it to False. Do NOT use an if statement in your solution. Assume jellybeans and licorice already have values.
>
> The answer is: delicious = jellybeans > 20 or licorice > 30 or jellybeans + licorice > 40
>
> What are yalls thoughts?
The bottom line is, does it work?
Did you test it? That is, did you try all the different
combinations of values for the variables and get the
right result from your expression, both True and False.
You might also want to consider adding parentheses
just for improved readability.
--
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
More information about the Tutor
mailing list