Pyhton fizzbuzz | SoloLearn: Learn to code for FREE!

0

Pyhton fizzbuzz

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 PM

Ozemoka Shuaib Aloaye

16 Answers

New Answer

+3

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)

+5

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.

+4

BTW it's Python and not Pyhton.

+3

Sonic yes thank you i will put that into my head that i dont know the correct spelling of python

+3

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.

+2

+2

Ozemoka Shuaib Aloaye lol that's OK. I'm sure it was a typo.

+2

Sonic ya it was. And by the way thanks alot

+2

Abhay hey the code didn't work tho

+2

I just tried kt

+2

+1

Drishti let me try it

+1

Drishti Thanks it worked..... Thanks alot

+1

Ozemoka Shuaib Aloaye in the original code you posted, change the "else if" to "else"

+1

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

-1

<Try this> https://code.sololearn.com/c19NY4J0Z5lq/?ref=app