r/pythonhelp • • Jun 06 '22

FizzBuzz Problem

Hello,

I am struggling with a practice FrizzBuzz problem.

def StringChallenge(num):
    for i in range (1, num+1):
        if(i % 5 == 0 and i % 3 == 0):
            print("FizzBuzz", end = ' ')
        elif(i % 5 == 0):
            print("Buzz", end = ' ')
        elif(i % 3 == 0):
            print("Fizz", end = ' ')
        else:
            print(i, end = ' ')
            
    return num
print(StringChallenge(input()))

I am trying to make it work so it all outputs on the same line. The first line and last two lines are required.

0 Upvotes

5 comments sorted by

View all comments

1

u/AmongstYou666 Jun 07 '22

  
def  StringChallenge(num):
    for  i  in  range  (1,  num+1):
        if (not i%5 and not i%3):
            print("FizzBuzz",  end  =  '  ')
        elif (not i%5):
            print("Buzz",  end  =  '  ')
        elif (not i%3):
            print("Fizz",  end  =  '  ')
        else:
            print(i,  end  =  '  ')
                        
StringChallenge(int(input('number  ')))
print()