dimanche 18 mars 2018

Python if, elif

It's really basic stuff but it gets on my nerves; Why this code doesn't work properly?

for i in range(0, 101):
if i % 3 == 0 and i != 0:
    print '{} Three'.format(i)
elif i % 5 == 0 and i % 3 == 0 and i != 0:
    print '{} FiveThree'.format(i)

else:
    print "{}".format(i)

Is it because of conditions? So if I want to write the code in this form I must write the complicated condition first and then the simple one?

Aucun commentaire:

Enregistrer un commentaire