lundi 7 septembre 2020

problem with if else loop for a month and days problem

why do I get the wrong output for the code below, I've put the output below

(some might suggest using date-time module, I'm going with this method due to some complications with the main program)

    months = [1,2,3,4,5,6,7,8,9,10,11,12]
    for month in months:
        if month == {1,3,5,7,9,11}:
            days= 31
            print(days)
        elif month == {4,6,8,10,12}:
            days = 30
            print(days)
        else :
            days = 28
            print(days)

I get this output

    28
    28
    28
    28
    28
    28
    28
    28
    28
    28
    28
    28

Aucun commentaire:

Enregistrer un commentaire