[Tutor] Problem with if statements and else statements

Mats Wichmann mats at wichmann.us
Sun May 28 16:13:16 EDT 2017


On 05/27/2017 06:14 PM, boB Stepp wrote:
> Hello Jalen!
> 
> On Sat, May 27, 2017 at 4:19 PM, Jalen Barr <jalenbarr1 at gmail.com> wrote:
>>
>> In this code it always changes the PlaceHolder to 0 no matter what Month is
>> set to
>>
>> Month ="September"
>>
>> if Month == "January" or "1":
>>     PlaceHolder = 0
> 
> This must be written as:
> 
> if Month == "January" or Month == "1":
>     PlaceHolder = 0
> 
> The way you wrote it is interpreted as:
> 
> if (Month == "January") or ("1"):
>     PlaceHolder = 0

and since "1" is always True, PlaceHolder is always set to 0.

FWIW, if checking for multiples, you could also write:

if Month in ['January', '1']:






More information about the Tutor mailing list