0

# My FizzBuzz code

I don't seem to know the bug or problem to my code, it's just that the Test Case 1 is correct but the compiler said that I should debug it and change the code. n = int(input()) for x in range(1, n): if x % 2 == 1: if x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") elif (x % (3 and 5)) == 0: print("SoloLearn") else: print(x) elif x % 2 == 0: continue The expected output has been met with the output of my code. Please help.

30th Dec 2020, 12:54 AM
Paul Toque
5 Réponses
+ 9
The condition (x % (5 and 3) == 0) should be (x % 5 == 0 and x % 3 == 0) and it should be at the top of the nested if-elif-else statement because if it comes last then it will never become true because the if's above it will also meet the condition before it. And just a question because I dont know the details of the challenge. Do the solver needs to iterate all numbers? Or just odd numbers? Thanks the answer would be a big help. Anyway, please update me if it is still not solved and if you need more explanation, feel free to ask. Thanks! https://code.sololearn.com/c2A1A155a9a2 https://code.sololearn.com/ca18A200a12a
30th Dec 2020, 1:07 AM
noteve
+ 2
number = int(input("")) for x in range(1,number): if x % 2 == 0: continue elif x % 5 == 0 and x % 3 == 0 and x % 2 == 1: print("SoloLearn") elif x % 3 == 0 and x % 5 != 0 and x % 2 == 1: print('Solo') elif x % 5 == 0 and x % 3 != 0 and x % 2 == 1: print("Learn") elif x % 5 != 0 and x % 3 != 0 and x % 2 == 1: print(x)
30th Dec 2020, 3:42 AM
K.S.S. Karunarathne
+ 2
Problem 1 : On line 9 : The syntax of this expression in incorrect. It should be written like that (x%3 and x%5) Problem 2 : On line 13 : It should be an "else" statement as there's no any other condition beyond that line. :)
30th Dec 2020, 4:04 AM
Ali Bin Faizan
+ 2
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)
30th Dec 2020, 6:48 AM
Roma Butaku
+ 1
Wow, your code works. So the only problem that I can't seem to figure out is that the x % 5 == 0 and x % 3 == 0 is not placed on the top of the nested if-elif-else statement. And I still can't figure what's the difference between the two. I appreciate your help :).
30th Dec 2020, 1:23 AM
Paul Toque