[Tutor] Python help

Alan Gauld alan.gauld at btinternet.com
Mon Apr 2 20:34:24 EDT 2018


On 03/04/18 01:19, Steven D'Aprano wrote:
> On Tue, Apr 03, 2018 at 01:00:59AM +0100, Alan Gauld via Tutor wrote:
>
>> You need to use 'in' instead. That will check whether
>> or not Grade is *one* of the values in the tuple.
>>
>>     if Grade not in 'A','B','C','D','E','F':
> Actually, that returns a tuple consisting of a flag plus five more 
> strings:
>
> py> 'A' in 'A','B','C', 'D', 'E', 'F'
> (True, 'B','C', 'D', 'E', 'F')
>
> We need to put round brackets (parentheses) around the scores:
>
>     if Grade not in ('A','B','C','D','E','F'):

Oops, yes, a cut n' paste error, I forgot to add the parens.
mea culpa!

-- 

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