+ 2
FIZZBUZZ QUESTION
It takes an input n and outputs the numbers from 1 to n. For each multiple of 3, print "Solo" instead of the number. For each multiple of 5, prints "Learn" instead of the number. For numbers which are multiples of both 3 and 5, output "SoloLearn". You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range.
8 Answers
+ 3
Denise RoĂberg My program starts from 1 in all conditions and goes up to the number entered by user. Since all odd numbers are required, I am updating value of i with 2
+ 3
Adi Nath Bhawani
Ah, okay. Now I got it. đ
+ 2
Hello Sheikh Mohammed Ahmedraza
Please show us your code so that we can help you.
+ 2
n=int(input("Enter number"))
for i in range(1,n+1,2):
if(i%15==0):
print("SoloLearn")
elif(i%5==0):
print("Learn")
elif(i%3==0):
print("Solo")
else:
print(i)
+ 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")
else:
print(x)
continue
>>>>this is the given code, we have to correct or edit it to get correct answer
+ 2
Sheikh Mohammed Ahmedraza
Add the beginning you need to check if x % 2 == 0
if x % 2 == 0:
continue
elif...
You need to put it at the beginning because e.g. 6 is divible by 3
btw: you can simplify x%3 and x%5 to x%15
elif x%15:
+ 2
Adi Nath Bhawani
I would say your code won't work if you enter an even number.
e.g. 10, then it gets 12, 14....
0
you should first exclude the even numbers
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)