0

How to I run the FizzBuzz function for only odd numbers

Here is my code: n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x) I want to run and work this code only for odd numbers.

19th Oct 2020, 12:57 AM
ASHRAFUL HAQUE SULAIMAN
ASHRAFUL HAQUE SULAIMAN - avatar
2 Respostas
+ 6
Use the range stepping parameter to set the range increment. for x in range( 1, n, 2 ): This way the loop starts by 1, and increment by 2 on each round ( 1, 3, 5, 7, ... )
19th Oct 2020, 4:08 AM
Ipang
+ 3
Add another if condition below for loop to check odd numbers. If it's odd execute body of loop
19th Oct 2020, 1:12 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar