0

Who can help me using the continue statement

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.

16th Jan 2022, 11:07 AM
Wijdene Madiouni
Wijdene Madiouni - avatar
5 Antworten
+ 1
Can you please link your code?
16th Jan 2022, 11:11 AM
Lisa
Lisa - avatar
+ 1
Lisa 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)
16th Jan 2022, 11:14 AM
Wijdene Madiouni
Wijdene Madiouni - avatar
+ 1
n=int(input()) for x in range (1,n,2): 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 already solved the project and above is my solution.
18th Jan 2022, 10:24 AM
SK SANOWAR
0
There's another condition in the task description: Do not print if the number is even. I suggest you to first check in x is even, and if so "continue". Then go on (elif) with the conditions that you already implemented.
16th Jan 2022, 11:18 AM
Lisa
Lisa - avatar
0
Wijdene Madiouni To skip even numbers, use the third argument in range() to specify an increment of 2 instead of the default of 1. So it will start with 1, skip to 3, then 5, ... and so on.
16th Jan 2022, 3:18 PM
Brian
Brian - avatar