16 AnswersNew Answer
FizzBuzz is a well known programming assignment, asked during interviews. The given code solves the FizzBuzz problem and uses the words "Solo" and "Learn" instead of "Fizz" and "Buzz". 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. https://code.sololearn.com/chol6l4VB3eD/?ref=app
1/25/2021 12:03:06 PMOzemoka Shuaib Aloaye
16 AnswersNew Answer
Next time ask the actual query instead of letting us play a guess game on what actual problem is . for x in range(1, n): if x % 5 == 0 and x % 3 == 0: print("SoloLearn") continue elif x % 3 == 0: print("Solo") continue elif x % 5 == 0: print("Learn") continue else: print(x)
n = int(input()) for x in range(1, n , 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) Just add "2" in the range.
BTW it's Python and not Pyhton.
Sonic yes thank you i will put that into my head that i dont know the correct spelling of python
To skip even numbers, you need to code it out. The multiples of 3, multiples of 5, and multiples of 3 and 5 has been coded already. Even number means multiples of 2. I'm not sure if this applies but the API is: range(start, stop, step) start defaults to 0 (inclusive) stop is compulsory (exclusive) step defaults to 1 You might want to change line 3: "range(1, n)" to "range(1, n+1)". So that your input value is included. You can also set the step=2 to increment by 2 to skip even numbers.
Ozemoka Shuaib Aloaye lol that's OK. I'm sure it was a typo.
Sonic ya it was. And by the way thanks alot
Abhay hey the code didn't work tho
I just tried kt
Drishti let me try it
Drishti Thanks it worked..... Thanks alot
Ozemoka Shuaib Aloaye in the original code you posted, change the "else if" to "else"
it might be a fairly obvious answer but can someone please explain this " else: print (x)" this was the part i was missing in my code and im having trouble understanding
<Try this> https://code.sololearn.com/c19NY4J0Z5lq/?ref=app
SoloLearn Inc.4 Embarcadero Center, Suite 1455
Send us a message