Q. Write a program to take N(N>20) as an input from the user. print number from 11 to N. When the number is multiple of 3, print "tipsy". when it is multiple of 7 print "topsy". When it is a multiple of bothprint "tipsyTopsy".
You can understand by Watching video :-
Answer :
By for loop method
n = int(input("enter a number greater than 20 = ")) for i in range(11,n+1): if i % 3 == 0 and i % 7==0 : print(i,"tipsytopsy") elif i % 3==0 : print(i,"tipsy") elif i % 7==0 : print(i,"topsy")
By while loop method
n = int(input("enter a number greater than 20 = ")) i = 11 while i <= n : if i % 3 == 0 and i % 7==0 : print(i,"tipsytopsy") elif i % 3==0 : print(i,"tipsy") elif i % 7==0 : print(i,"topsy") i += 1
Output :-
Enter a number greater than 20 = 25
12 tipsy
14 topsy
15 tipsy
18 tipsy
21 tipsytopsy
24 tipsy
>>>
Enter a number greater than 20 = 49
12 tipsy
14 topsy
15 tipsy
18 tipsy
21 tipsytopsy
24 tipsy
27 tipsy
28 topsy
30 tipsy
33 tipsy
35 topsy
36 tipsy
39 tipsy
42 tipsytopsy
45 tipsy
48 tipsy
49 topsy
>>>
Please show the same answer using while loop
ReplyDeleteOk , Please Check again : )
DeletePlease ask .
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )