Teaser-1 (Python If, Elif)

1. Write a Python function that prints the numbers from 1 to 100. But for multiples of three, print “three” instead of the number, and for the multiples of five, print “five”. For numbers which are multiples of both three and five, print “threefive”.
 

def three_five():
       for i in range(1, 101):
             if i % 3 == 0 and i % 5 == 0:
                 print(“threefive”)
             elif i % 3 == 0:
                 print(“three”)
             elif i % 5 == 0:
                 print(“five”)
             else:
                 print(i)

three_five()

Leave a Reply