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
3 Respuestas
+ 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'
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
0
The sequence of conditions in the if-elif-else statement matters.