Python Forum
invalid syntax on Python 3.8.2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
invalid syntax on Python 3.8.2
#1
Hello. My Terminal cannot execute what I write on IDLE.
The input was very simple.
x="hello"
print(x)

What do I have to do on Python 3.8.2 with '^' mark?
I asked an assistant of University professor, but he cannot answer...

Below is the output from Terminal.
/////////////////////////////////////////////
ren@RENs-MacBook-Pro ~ % python hello2.py
File "hello2.py", line 1
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)
^
SyntaxError: invalid syntax
ren@RENs-MacBook-Pro ~ % python3 hello2.py
File "hello2.py", line 1
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)
^
SyntaxError: invalid syntax
//////////////////////////////////////////////
Reply
#2
the code is
x="hello"
print(x)
you should not include anything else
also look at https://python-forum.io/Thread-How-to-Ex...ython-code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
The code is exactly what you wrote which is the same as I wrote.
Please see the screenshot in my (new)blog.

[Image: entry-12590693327.html]
Reply
#4
The traceback and screenshot is clear. the first line in your py file is
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) 
probably you copy paste some code from python shell into py file and in addition to code you sopy/paste this (and probably other) unnecessary line. check the link in my previous post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
I wrote it by myself on IDLE (Python 3.8.2 shell) and saved on MacBook Pro (Catalina).
Before I posted my Thread, I check the link you referred. But there was no answer with '^' mark on 3.8.2 at Terminal notification.
Reply
#6
The idea of the link is to understand different ways to execute python code.
1. In interactive shell:
Python 3.7.7 (default, Mar 10 2020, 17:25:08) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'hello'
>>> print(x)
hello
>>> 
so, this part
Output:
Python 3.7.7 (default, Mar 10 2020, 17:25:08) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information.
is the header of the python shell, it should not go in file.

In file you should have just
x="hello"
print(x)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
When you in IDLE you most do File --> New File
This is the Window you write or paste in code.
Now File --> Save as eg hello2.py.
Same Window Run --> Run Module(F5).
Reply
#8
Dear Snippsat,

The problem is solved with the way you taught!
Thank you so much!!

The problem is solved!

Best Regards,

REN
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020