FizzBuzz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

FizzBuzz

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.

29th Aug 2022, 6:14 PM
Ebube Okpala
Ebube Okpala - avatar
5 Answers
+ 4
Sample input 15: which covered by first if condition so prints "Solo" But it is also divisable by 5 so must output "Sololearn". Reverse conditions: first check for both, then check for 3 and then for 5. For skipping even numbers, you can use range() third parameter 'increment counter ' value. edit: your conditions only skips those even numbers which are divisable by 3 or 5 or both. not all.....
29th Aug 2022, 6:59 PM
Jayakrishna 🇮🇳
+ 4
Ebube Okpala , (1) we should keep the sequence for the conditionals as it is given from sololearn, this should be on top of the 3 conditional branches: if x % 3 == 0 and x % 5 == 0: (2) to avoid checking for even / odd numbers in all 3 conditional branches, it should be done only once. we should check this at the very top. in case the generated number from the loop is even, the program should start the next iteration.
29th Aug 2022, 7:10 PM
Lothar
Lothar - avatar
+ 2
Okay, Thank you so much
29th Aug 2022, 10:04 PM
Ebube Okpala
Ebube Okpala - avatar
+ 1
Your attempt?
29th Aug 2022, 6:26 PM
Jayakrishna 🇮🇳
+ 1
n = int(input()) for x in range(1, n): if x%3 == 0 and x%2 != 0: print("Solo") elif x%5 == 0 and x%2 != 0: print("Learn") elif x%3 == 0 and x%5 == 0 and x%2 != 0: print("Sololearn") else: print(x)
29th Aug 2022, 6:27 PM
Ebube Okpala
Ebube Okpala - avatar