+ 1

There is a certain modifications that this code correct I can't solve them any help!!!

FizzBuzz is a well known programming assignment, asked during interviews. The given code solves the FizzBuzz problem and uses the words "Solo" and "Learn" instead of "Fizz" and "Buzz". It takes an input n and outputs the numbers from 1 to n. For each multiple of 3, print "Solo" instead of the number. For each multiple of 5, prints "Learn" instead of the number. For numbers which are multiples of both 3 and 5, output "SoloLearn". You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range. 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)

9th Jan 2022, 7:49 AM
Wijdene Madiouni
Wijdene Madiouni - avatar
4 odpowiedzi
+ 5
You need to skip even numbers. It can be done using continue statement or taking a suitable step value in range()
9th Jan 2022, 8:01 AM
Simba
Simba - avatar
+ 4
How do you find even numbers? After finding them use continue statement instead of print() That's how continue skips iterations.
9th Jan 2022, 8:05 AM
Simba
Simba - avatar
+ 1
How can I use the continue statement
9th Jan 2022, 8:02 AM
Wijdene Madiouni
Wijdene Madiouni - avatar
0
Mustafa Ansari instead of doing mod division operation, the answer is stored in x, itself. Just examine the lowest bit: if x&1==0: continue But the very best way to skip even numbers is to adjust the range to imcrement past even numbers, as Simba recommended. for x in range(1, n, 2):
9th Jan 2022, 10:36 PM
Brian
Brian - avatar