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.
2 Answers
+ 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, ... )
+ 3
Add another if condition below for loop to check odd numbers. If it's odd execute body of loop