+ 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)

18th Jun 2018, 10:53 AM
Rprogramar
Rprogramar - avatar
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)
18th Jun 2018, 11:02 AM
Fermi
Fermi - avatar
18th Jun 2018, 12:17 PM
Rprogramar
Rprogramar - avatar
+ 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
18th Jun 2018, 11:00 AM
ŠŁÄšźőňĘü