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
4
  • 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? Commented Aug 30, 2022 at 5:33
  • I run on MacOS and use VSCode. I use the default save and run python file on VSCode @ThomasWeller Commented Aug 30, 2022 at 5:35
  • 3
    Somehow you're trying to run your program from within the Python interpreter. It should be run from the shell instead. Commented Aug 30, 2022 at 5:41
  • 1
    Does this answer your question? Invalid Syntax error when running python from inside Visual Studio Code Commented Aug 30, 2022 at 5:42

1 Answer 1

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.