+ 2
Why doesn't this work?
I wrote some code for a py simulation of FizzBuzz, but I can't seem to be able to get it to work. Does anyone know why? i = 1 while i <= 100: i == i + 1 Output = "" if i % 3 == 0: Output += "Fizz" if i % 5 == 0: Output += "Buzz" if Output == "": Output == i print(Output)
3 Antworten
+ 5
== is used for comparison for equality, = is for assignment.
i = 0
while i <= 100:
i = i + 1
Output = ""
if i % 3 == 0:
Output += "Fizz"
if i % 5 == 0:
Output += "Buzz"
if Output == "":
Output = str(i)
print(Output)
+ 5
Thanks all! It works!
https://code.sololearn.com/clO8E2ENQfJP/?ref=app
+ 2
i = 1
while i <= 100:
Output = str(i)+" "
if i % 3 == 0:
Output += "Fizz"
if i % 5 == 0:
Output += "Buzz"
print(Output)
i = i+1
#You may mean i=i+1 rather than i==i+1