lundi 31 juillet 2017

Using multiple Ifs in python that are not mutually exclusive

a=0
while a<30:
    a+=1
    print(a)
    if a%3==0:
        print("This is a multiple of 3.")
    if a%5==0:
        print("This is a multiple of 5.")
    else:
        print("This is not a multiple of 3 or 5.")

I'd like for this else statement to only print if NEITHER of the previous if statements are true. I don't want to use if, elif, else because the variable could be both a multiple of 3 and 5.

Aucun commentaire:

Enregistrer un commentaire