lundi 27 septembre 2021

How can I check if number is multiple of 3 or contains the digit 5?

digit = 5
for i in range(1, 101):
    if i % 3 == 0:
        print ("MultipleOfThree", end=" ")
    elif i:
        for digit in str(i):
            print ("FiveInIt", end=" ")
    else:
        print(i, end=" ")

I want to see in one line like that:

1 2 MultipleOfThree 4 FiveInIt MultipleOfThree 7 8 MultipleOfThree 10 11 MultipleOfThree 12 13 14 FiveInIt ........ 

But the output gives:

FiveInIt FiveInIt MultipleOfThree FiveInIt FiveInIt MultipleOfThree .......

Aucun commentaire:

Enregistrer un commentaire