I can't solve the fizzbuzz challenge in python just why my code outputs this ? | Sololearn: Learn to code for FREE!
0

I can't solve the fizzbuzz challenge in python just why my code outputs this ?

my 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 not x % 2 == 0: print(x) output 1 solo learn solo 7 solo learn 11 solo 13

19th Mar 2022, 3:28 PM
Ziad AbdElkawy
10 Réponses
+ 5
I see...the challenge requires only the odds. This check must be first one or....much better be part of range range(1,n+1,2)
19th Mar 2022, 3:52 PM
Oma Falk
Oma Falk - avatar
+ 4
Let's see what happens to 8: Not Sololearn Not Solo Not Learn Not 8 ... replace last elif by a simple else
19th Mar 2022, 3:41 PM
Oma Falk
Oma Falk - avatar
+ 3
Jayakrishnaūüáģūüá≥ n = int(input()) for x in range(1, n+1,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) I have to edit this code to skip the even numbers it is in python core u can see it yourself it is the fizzbuzz challenge
19th Mar 2022, 4:34 PM
Ziad AbdElkawy
+ 1
just put a condition to check number is not even: if x % 2 != 0: 'enter your code here' n = int(input()) for x in range(1, n): if x % 2 != 0: if x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn")
21st Mar 2022, 6:43 AM
Yash Sonani
Yash Sonani - avatar
0
Add task description also... Is it asked to print fizzbuzz or sololearn..? Is that range includes n also? If no for both , then code is fine.
19th Mar 2022, 3:36 PM
Jayakrishna ūüáģūüá≥
0
Oma Falk it makes a wronge
19th Mar 2022, 3:45 PM
Ziad AbdElkawy
0
Jayakrishnaūüáģūüá≥ sololearn no n isn't included and my code doesn't match with the correct code
19th Mar 2022, 3:51 PM
Ziad AbdElkawy
0
Oma Falk it failed but si close my code is prints the same as answer but it prints sololearn at the end of the code wich is wronge.
19th Mar 2022, 4:01 PM
Ziad AbdElkawy
0
Pls post full description..
19th Mar 2022, 4:13 PM
Jayakrishna ūüáģūüá≥
0
Ziad AbdElkawy ok. there It asked to skip even numbers. so just Making range(1, n) to range(1, n, 2) works well. But your way, you're using skip at last, but ex : 6 it's 6%3==0 printing 'Solo', but it need to skip. You should add last if condition in first place. But skip by range is efficient..
19th Mar 2022, 4:46 PM
Jayakrishna ūüáģūüá≥