0

I am having problems with a simple program I wrote but do not know where the problem is, and it is giving me a Syntax error.

This is my code:

username = {}
temp = True
while temp:
    name = input("Please input your username: ")
    response = input("What is the place you want to visit? ")

    username[name] = response

    end = input("Do you want to end the program? Yes/No ")
    if end == 'Yes':
        temp = False

print("These are the results of the poll: ")

for names, responses in username.items():
    print(names + " wants to go to " + responses)

This is my error:

File "<stdin>", line 1
    /usr/local/bin/python3 "/Users/eric/Python Notes/Notes.py"
    ^
SyntaxError: invalid syntax
LilPotato
  • 13
  • 3
  • There is no problem with your Python code (at least not the code your posted here). The problem is in how you run it. What is your OS? What is your IDE? How do you run the program? – Thomas Weller Aug 30 '22 at 05:33
  • I run on MacOS and use VSCode. I use the default save and run python file on VSCode @ThomasWeller – LilPotato Aug 30 '22 at 05:35
  • 3
    Somehow you're trying to run your program from within the Python interpreter. It should be run from the shell instead. – Thomas Weller Aug 30 '22 at 05:41
  • 1
    Does this answer your question? [Invalid Syntax error when running python from inside Visual Studio Code](https://stackoverflow.com/questions/51540391/invalid-syntax-error-when-running-python-from-inside-visual-studio-code) – Thomas Weller Aug 30 '22 at 05:42

1 Answers1

0

Check out the accepted answer here:

syntax error when using command line in python

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.

There are also some VSCode-specific tips here:

Invalid Syntax error when running python from inside Visual Studio Code

ljdyer
  • 1,946
  • 1
  • 3
  • 11