Hello world invalid syntax

Hello :slight_smile:
Could anyone explain me please how to fix it.


.

I just watching first video by Corey Schafer and do exactly the same but already error…

I can’t open saved file. When in python terminal or cmd i type: python/Desktop.intro.py i have invalid syntax… I’m sorry for silly question.

Thank you.

That command is intended for the Windows command line, but you typed it at the Python prompt.

Incidentally, on Windows it’s recommended that you use the Python Launcher py:

py %USERPROFILE%\Desktop\intro.py

(%USERPROFILE%\Desktop will give you the path to the desktop on Windows.)

Sorry, it is not working at all…
Look please in his video, he does absolutely the same as me(i do the same :)) )
when he types all good, when i, it’s always error :frowning:

It’s already been mentioned but you have typed python into the python interpreter in your first screenshot.

In the video they have typed python into a shell.

These are not the same thing.

You may have not used a shell before, in which case you should look into learning how to do so.

Git bash/git for windows is an easy way to get started, but once you are more confident you might want to look at using the Windows subsystem for Linux (WSL2).

None of this is python specific, this is about becoming computer literate to the level required to be a productive programmer.

The commands have to be entered in the right context, as the other posts have mentioned. You can look at the prompt for a hint about what context you’re currently in:

  • >>> means that you’re in the Python interpreter, so it’s expecting you to enter a Python statement.
  • $ means that you’re at the bash shell prompt, so it’s expecting you to enter a Linux command.
  • # would mean the same when you’re logged in as root (i.e. with admin privileges).
  • C:\> (or similar) would mean you’re at the Windows command prompt, so it’s expecting a DOS/Windows command.

In the screenshot from the video, you can see that he

  1. starts off at the $ prompt and executes a Linux command to start Python,
  2. then enters some Python code at the >>> prompt and exits with exit(),
  3. then, back at the $ prompt, executes Linux commands again to launch Python with the file Desktop/intro.py.

That said, if you just want to run your program from IDLE, you can select “Run module” from the “Run” menu in your editor window (or press F5).

2 Likes