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
10 Answers
+ 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)
+ 4
Let's see what happens to 8:
Not Sololearn
Not Solo
Not Learn
Not 8
... replace last elif by a simple else
+ 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
+ 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")
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.
0
Oma Falk it makes a wronge
0
Jayakrishna🇮🇳 sololearn
no n isn't included
and my code doesn't match with the correct code
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.
0
Pls post full description..
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..