Elementary error

help! please and thank you.

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 i don’t know where to find the debug hotkeys. 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!

you need to use Pythonic syntax. if statements in Python typically are not inside print statements. what I think you meant to write is this

v=input('?')
if v % 3 == 0:
    print('fizz')
elif v % 5 ==0:
    print('buzz')

Python is based on spacing so you need to stick to either tabs or four spaces for if statements, functions and stuff like that.

1 Like

hi, thank you for your reply. yes, your way works. but before posting, i found several python references that seem to show my way should work, and yet it doesn’t.

if you can cite the references I could look at them and see what’s different.

aargh! when i went back to look again, i realized i misread them. the two examples i found were of what NOT to do, but confusing due to the context.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

ok, thank you, that looks more professional…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.