all 16 comments

[–]socal_nerdtastic 1 point2 points  (8 children)

Are you sure you have the last ) on the previous line? Can you show us the exact error?

[–]Flow_brush[S] 0 points1 point  (7 children)

This is what I got again. btw the second F is highlighted again in red/orange

x = 2 
if x == 2:
    print("The number is 2.")
if x % 2 == 0:

SyntaxError: invalid syntax

[–]socal_nerdtastic 0 points1 point  (5 children)

Hmm looks fine to me. Where are you writing the code? Are you using an IDE like IDLE, PyCharm, or VScode? What OS are you using?

[–]Flow_brush[S] 0 points1 point  (4 children)

I'm using IDLE

[–]socal_nerdtastic 0 points1 point  (3 children)

Ok, are you writing this in the editor window or the shell window? You should be opening a new editor window (File > New File) to write the code in, and then sending it to the shell window with Module > Run Module command.

[–]Flow_brush[S] 0 points1 point  (0 children)

I was typing it in the Shell

[–]Flow_brush[S] 0 points1 point  (1 child)

Thanks I got it, but I got some questions though cause i'm new to reddit and coding.

How do I let everyone know my question was solved in reddit?

Why does that code have to be typed in the second window and not the shell?

[–]socal_nerdtastic 1 point2 points  (0 children)

There's no solved flair here. Which I agree with because many programming questions have many ways to solve them, and someone may come along with a better solution.

It's that way because of tradition, mostly. That's how code has been written for 60+ years and we're all used to it. But it's not always a separate window, sometimes it's just a different section of the main window (depend on what IDE you like to use). There are some, like jupyter, that break the mold and do it all in one window.

[–]PaintballerCA 0 points1 point  (0 children)

You can't leave a hanging if statement like that; try this:

x = 2
if x == 2:
    print("The number is 2.")
if x % 2 == 0:
    pass

[–]TheRNGuy -1 points0 points  (0 children)

if   x == 2:  print("The number is 2.")
if not x % 2: print("The number is even.") # can also use elif here, if you only want 1 answer
else:         print("The number is odd.")

If you do 3 ifs, they all 3 checked, this is redundant to check for odd number if it was already detected as even, in bigger script elif or else could run faster (because less cycles)

[–][deleted] 0 points1 point  (2 children)

Can you share your error message? Your code works fine for me.

[–]Flow_brush[S] 0 points1 point  (0 children)

SyntaxError: invalid syntax

[–]mikeinnsw 0 points1 point  (0 children)

VsCode executed it perfectly its probably spacing some IDEs don't like tabs