Python Mastery - Formatted Strings Syntax Error

Hello All,

Thank you in advance for any help. I am getting a syntax error on line 3. The code matchs Mosh’s and I’ve installed all the correct extensions so far. I’ve even tried running the code in pythontutor.org and it works there. Thank again for any help.

Hello, and welcome!

That’s weird. I checked your code and it works perfectly :face_with_monocle:

I’ve seen similar behaviour when indenting, but I see no indentation in your code :face_with_monocle: :face_with_monocle:

Since it works on www.pythontutor.com you can be sure that your code works, and that’t the important point here.

Now it would be interesting to figure it out why a perfectly written code doesn’t work in VSCode. For this I would:

  1. Open a new file and write the code again. If it still doesn’t work,
  2. Open a Python file from another user, where the code DID work. Here GitHub - NickATC/test_files: Files to test and share you will find a test.py file. download it and test it on your computer.
  3. Install another code editor (Notepad++, Atom, etc…), open a new file and write the code again.

I’m pretty sure that at this point, that you will make some findings.

Anyway, let me know if step 1 worked.

It looks like you’re using a rather old (prior to 3.6) version of python. Run python --version to be sure.

Hi,

I had the same issue on Mac and I have sorted it with the following:

1: settings
2: in the search bar type: code-runner.executorMap
3: click Edit in settings.json
4: after the last code type a comma and press enter
5: on the next line type as follow “code-runner.executorMap”
6: lots of new codes will be displayed
7: amend the the python code (on mine it was on line 14) showing as
“python”: “python -u”, as follow:
“python”: “python3”,
8: save and exit

After this amendment, the formatting string started to work.

For help refer to “Lesson 9” of Getting Started. It is not the same on newer versions but the above should help.

I hope this helps