0

Help - Python - 30. FizzBuzz

Can someone explain to me why the following codes have different results? CODE 1 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) RESULT 1 1 Solo Learn 7 Solo 11 13 CODE 2 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) RESULT 2 1 Solo Learn Solo 7 Solo Learn 11 Solo 13

3rd Nov 2021, 12:10 PM
Lee Vitout
Lee Vitout - avatar
3 Answers
+ 1
in the code 1- checking even or odd at the beginning x%2==0 so no ouput for 10 in the code 2- at the end checking so 10 is divisible by 5 that outputs 'Learn'
3rd Nov 2021, 1:51 PM
Krishnam Raju M
Krishnam Raju M - avatar
0
One thing jumping out is the number 10. In the first one, 10 is even so it continues. In the second one, its divisible by 5 so "Learn" is printed. There's other things but this jumped out
3rd Nov 2021, 12:15 PM
Slick
Slick - avatar
0
The sequence of conditions in the if-elif-else statement matters.
3rd Nov 2021, 2:00 PM
Lisa
Lisa - avatar