Programming Examples

Python program to Print numbers from 11 to N When the number is a multiple of 3 print Tipsy when it is a multiple of 7 print Topsy


Write a program to take N (N > 20) as an input from the user. Print numbers from 11 to N. When the number is a multiple of 3, print "Tipsy", when it is a multiple of 7, print "Topsy". When it is a multiple of both, print "TipsyTopsy".

Solution

n = int(input("Enter a number greater than 20: "))
if n <= 20 :
    print("Invalid Input")
else :
    for i in range(11, n + 1) :
        print(i)
        if i % 3 == 0 and i % 7 == 0 :
            print("TipsyTopsy")
        elif i % 3 == 0 :
            print("Tipsy")
        elif i % 7 == 0 :
            print("Topsy")
Output

Enter a number greater than 20: 25

11

12

Tipsy

13

14

Topsy

15

Tipsy

16

17

18

Tipsy

19

20

21

TipsyTopsy

22

23

24

Tipsy

25

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz