New here and hoping I can help as much as I am helped. Basically, I have been tasked with writing a fizzbuzz program in Python and so far so good except for some feedback I received.
Now I have to ensure that the output of my program comes across horizontally and is not printed vertically on new lines. From my understanding, and my lecturers hinting, I need to turn function to produce strings and remove the print statements as well.
Code is below:
def fizzbuzz1 (num):
for num in range(1, num):
if (num%3 == 0) and (num%5 == 0):
print("Fizzbuzz")
elif ((num % 3) == 0):
print("Fizz")
elif ((num % 5) == 0):
print("buzz")
else :
print (num)
def main ():
while True: #Just to keep my program up and running while I play with it
num = input ("please type a number: ") #
num = int (num)
print ("Please select an type what option you wish to try: A) Is this Fizz or Buzz? B) Count saying fizz/buzz/fizzbuzz")
opt = input ("Please type A or B and press enter: ")
if opt == "A":
fizzbuzz(num)
elif (opt == "a")
fizzbuzz(num)
elif (opt == "B"):
print (fizzbuzz1(num))
elif (opt == "b"):
print (fizzbuzz1(num))
main ()
I have tried a whole host of things, and my lecturer doesn't seem too interested in help me. Womp. I was recommended to review this exercise were I played with this piece of code:
def func(num):
value = ‘’
for x in range(...):
if .... == .... :
value += str(x) + ‘, ‘
return value[…]# You need to remove the last comma and the space
When I do play with this code, I do get numbers to go across the screen. But for the life of me I can not seem to incorporate what I have written with elements from this. Where am I going astray?
Thank you for any and all your advice/help. If you do choose to reply, please keep it as simple as possible for me.
Cheers.
Update: Thanks everyone for your suggestions, lots of thimgs I didnt know to try!
I also found a thread here at: Can't figure out how to print horizontally in python?
Which has answers to a similar issue.