+ 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.

9th Jan 2022, 8:21 AM
Sheikh Mohammed Ahmedraza
Sheikh Mohammed Ahmedraza - avatar
8 Réponses
+ 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
9th Jan 2022, 10:13 AM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
+ 3
Adi Nath Bhawani Ah, okay. Now I got it. ūüĎć
9th Jan 2022, 10:15 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Hello Sheikh Mohammed Ahmedraza Please show us your code so that we can help you.
9th Jan 2022, 8:38 AM
Denise Roßberg
Denise Roßberg - avatar
+ 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)
9th Jan 2022, 8:40 AM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
+ 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
9th Jan 2022, 8:43 AM
Sheikh Mohammed Ahmedraza
Sheikh Mohammed Ahmedraza - avatar
+ 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:
9th Jan 2022, 10:10 AM
Denise Roßberg
Denise Roßberg - avatar
+ 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....
9th Jan 2022, 10:11 AM
Denise Roßberg
Denise Roßberg - avatar
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)
30th Jul 2022, 12:29 PM
Tushar Kumar
Tushar Kumar - avatar