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

Python Control Structures FizzBuzz

My code is not working despite what seems to be identical output to what is proper. Also, for some reason my code stops outputting values after 5. There is no 7, 11, or 13. Can anyone explain this for me? Thx in advance. Here is the code: 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") elif x % 2 == 0: continue else: print(x) x+=1

16th Oct 2020, 11:48 AM
Dan
6 Answers
+ 3
What happens when x equals 6. It should skip the value. I think it will print 'Solo'. It is because the if/elif are in the wrong order. You should start with x % 2.
16th Oct 2020, 4:27 PM
Paul
Paul - avatar
+ 3
Add ( elif x % 2 == 0: Continue) in first elif condition rather than Last and don't add increment (x+=1) And everything reaming same.
17th Oct 2020, 2:46 PM
Abhishek Yadav
Abhishek Yadav - avatar
+ 2
I forrgot, you can scroll down in the output, if you don't see all the expected values.
16th Oct 2020, 4:33 PM
Paul
Paul - avatar
+ 1
Thanks Paul! I never considered that!
16th Oct 2020, 5:33 PM
Dan
0
I don't think there is a problem, though the x+=1 is superfluous, that doesn't affect the code. You code works fine to me and it does print 11 and 13 the odd numbers.
16th Oct 2020, 12:12 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Odd. Thx for help! I added the x+=1 when it didnt work at first lol thx for pointing that out tho
16th Oct 2020, 12:56 PM
Dan