+ 3

Help me for creating this teapot program

n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0 and x % 2 != 0: print("TEAPOT") elif x % 3 == 0 and x % 2 != 0: print("TEA") elif x % 5 == 0 and x % 2 != 0: print("POT") else: print(x) I want to skip all even numbers so only odd numbers get printed It’s a bit like FizzBuzz

8th Jan 2021, 5:29 AM
Yusuf M Hashmi
1 Réponse
+ 9
You can do this instead of typing x % 2 != 0 every condition: for x in range(1, n, 2): - - - - - - - - - - - - - - Parameters: range(start, end, step) So that when iterating, the even numbers are skipped because the iteration starts at 1 with 2 steps every iteration. Therefore the iteration will look like this: 1 3 5 7 ... n
8th Jan 2021, 5:40 AM
noteve
noteve - avatar