0

I just start learning python programming. I wrote a simple program in python 3.8.2:

x = "Hi world"
print (x)

Code was saved in a python file named 'file.py'. It ran correctly in python. The problem is when try to run the same chunk of code in the command line of windows 10.

After cmd was opened, i set the path at the directory where the file is saved, in this case, my desktop. Then i tried to run the next command:

C:\Users\Ben\Desktop>python file.py

The program was not work. Windows shows me the following message:

File "file.py", line 1 Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32 ^ SyntaxError: invalid syntax

I will appreciate all your help.

3
  • 1
    remove the >>> from your file Commented Mar 18, 2020 at 14:29
  • 2
    Please add the content of your file.py to your question (copy & paste). Likely you aren't using the normal " in your code. (Just to be sure, I'm assuming you aren't using these >>> in your file.py?) Commented Mar 18, 2020 at 14:29
  • Sorry. It is edited now ;) Commented Mar 18, 2020 at 14:56

1 Answer 1

1

If file.py just contained:

x = "Hi world"
print (x)

then that is fine but you have:

Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)]

as your first line.

This is most likely as it is imported from the default python IDLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.