Just learning Python and am getting a invalid syntax error. (Extreme noob here.)
syntax error when using command line in python - Stack Overflow
how do i fix syntax error in Python shell script? - Stack Overflow
Syntax Error in Python 3.10 when running on Terminal
I like to copy and paste examples from the teacher in python and play around with the new functions I am learning, but I can't figure out why I am getting an error.
def greet(lang):
if lang=='es':
print('Hola')
elif lang=='fr':
print('Bonjour')
else:
print('hello')
Looks like your problem is that you are trying to run python test.py from within the Python interpreter, which is why you're seeing that traceback.
Make sure you're out of the interpreter, then run the python test.py command from bash or command prompt or whatever.
You can simply type exit() in the Python terminal to exit the Python interpreter. Then when you run the code, there will be no more errors.