I’m trying to make a fizzbuzz program: count up to n; for each i up to n, print “fizz” if a multiple of 3, and “buzz” if a multiple of 5 — if a multiple of both, print “fizzbuzz”.
I’m using modular arithmetic, but for some reason my syntax is wrong.
Here is my code (without the “fizzbuzz” bit yet):
def fizzbuzz(n):
for i in range(n):
if i % 3 = 0
return fizz
if i % 5 = 0
return buzz
else
return i
print(fizzbuzz(100))
Error Code:
Python3IDE(Python 3.7) running!
File "/var/mobile/Containers/Data/Application/FD2AF249-3788-42B7-90B2-929E9D35A2E1/Documents/FizzBuzz.py", line 5
if i % 3 = 0
^
SyntaxError: invalid syntax
Pytho3IDE run end!
Any help is much appreciated.