N00b syntax c0nfusi0n

help! please and thank you. :nerd_face:

i’m just writing my first python code, the fizz-buzz thing, and getting syntax errors on this:

v=input("?")
print(“fizz” if v%3==0)
print(“buzz” if v%5==0)

i’ve tried every variant i can think of, and it doesn’t like it. wondering if perhaps i failed to install a necessary extension to VS, but the other simple stuff i did before this worked. super annoying.

also, i’m using a mac, and the debug keys Mosh uses in the videos don’t work the same way as when he made them. at one point i saw a small toolbar floating at the top of my code window, with debug icons, but it disappeared and i can’t find it now. also, when i try to fix the error and run again, i get a message that the code is already running, even though it stalled out.

fun!

hi, first of all when you use oneliner like:

“fizz” if v%3==0

it is required to also have else inside, here you can do something like :

"fizz" if v % 3 == 0 else None

The other thing is that your input always is of type string, so it cannot be compared with integer (like 3 or 5). You have to change it’s type like this:

int(input("?"))

So final code should look like this:

v = int(input("?"))
print("fizz" if v % 3 == 0 else None)
print("buzz" if v % 5 == 0 else None)

Hope this helps :slight_smile: