+ 3

You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range.

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 that 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 This is my code: n = int(input()) for x in range(1, n): if x % 2 == 0: continue #To skip even numbers elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x) So, here when I run the output: Test 1- passed Test 2: failed I'm unable to find the error of Test 2 since it's locked.

13th Aug 2021, 10:00 AM
Shree Harini
Shree Harini - avatar
4 Answers
+ 3
Shree Harini You didn't write a bit of code for %3 &%5 -> Sololearn See if this helps, your code with a tweak. Take note of the list slicing within your range call n = int(input()) for x in range(1,n,2): if x % 15 == 0: # %3 & %5 print("Sololearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
13th Aug 2021, 10:36 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Shree Harini A friend of mine just pointed out that the challenge requires an output of numbers from 1 to n. So I need to tweak my tweak. đŸ€ŁđŸ˜‚ for x in range(1, n+1, 2) # better
13th Aug 2021, 10:57 AM
Rik Wittkopp
Rik Wittkopp - avatar
13th Aug 2021, 10:07 AM
Ipang
+ 1
This is the correct code: n = int(input()) for x in range(1, n): if x % 2 == 0: continue elif x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
18th May 2022, 7:56 PM
Deborah Ogunwole