+ 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
6 Respostas
+ 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.
+ 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.
+ 2
I forrgot, you can scroll down in the output, if you don't see all the expected values.
+ 1
Thanks Paul! I never considered that!
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.
0
Odd. Thx for help! I added the x+=1 when it didnt work at first lol thx for pointing that out tho