Atom Quotation Marks Ex1 - 6 LTCTHW Python 3

So i have worked on this for about eight hours, i have uninstalled and reinstalled python 3.9, Atom and tried everything i can

But I still get an invalid syntax:

File “/Users/benodams/Desktop/Learn Python Coding/First Exercises/ex5.py”, line 9
print(f"lets talk about {my_name}.")
^
SyntaxError: invalid syntax
[Finished in 0.092s]

Its really, really, really frustrating and i am just about ready to set fire to my house with this - i have checked the code and everything its just not working. I have checked pages and pages but no one seems to have a solution i have seen this
Python 3 Ex5 Quotation mark syntax error but surely i shouldnt need to type in another programme to make it work?

Do i just skip these parts and hope for the best?
:face_with_symbols_over_mouth:

Can you copy and paste the whole file here with the lines before? Wrap it in code tags for the forum ([code]...[/code]) so we can see exactly what you wrote. Sometimes errors are caused by things earlier in the file.

Hi Florian,

Thanks for coming back to me. Will update tomorrow as I have stepped away from it.

Thanks

My money is that you are using python 2 local install and not python3.

Try running the file with python3 file.py

If python 2 is installed, for example on OS X, it will default to that instead of 3.9. And python 2 didn’t have format strings.

If that is the issue, try a quick Google of how to set python 3 as default.

Probably it’s not that line but a line before it. Python’s ability to tell you where an error really happens is fairly limited (although, it should be better at this). Imagine you have this:

print("I am a person"
print("I will print it")

If I throw that into a file named test.py and run it I get your error:

$ python test.py
  File "test.py", line 2
    print("I will print it")
        ^
SyntaxError: invalid syntax

Now, the actual error is on line 1 because I forgot a ) at the end of line one, but Python is stupid and keeps trying to parse line 1 bleeding into line 2 before it detects an error. It’s when it detects an error that it reports the line, not where the error really is.

That means if you keep looking at line 9 in your code and it looks fine, you have to go one line at a time backwards to find your errors. Line 8, 7, 6, 5 and so one.

The next thing to do is run your code more often. If you’ve got an error at line 9 and have no idea what line caused it then you probably wrote all the code and ran it once. How I code is I write 1 or 2 lines, run it, write 1 or 2 lines more, run it, and repeat until I’ve written all the code. You should be running your code once for every 1 or 2 “lines” of code.

The only caveat is sometimes you have to do this:

while true:
   pass

Pass tells python “I’ll fill this in later, so just pass it by”. Then you can run that to make sure it runs, and then fill in the while true.

Final recommendation: If you hit an error like this and you’re completely stuck, don’t spend a week staring at your code. Delete it and write it again, but do it slowly one line at a time. Think of programming like a video game named Rogue where you get to a point and die so you just start over, but each run through the dungeon is easier because you get better.

Let me know if that helped.

Hi All,

Thanks for taking the time to take a look - apologies for not sharing the code - here it is:
(Quote)
my_name = ‘Zed A. Shaw’
my_age = 35 #Not lying
my_height = 74 #inches
my_weight = 180 #lbs
my_eyes = ‘blue’
my_teeth = ‘white’
my_hair = ‘Brown’

print(f"lets talk about {my_name}.")
(end Quote)

this is leading to the trouble - in terms of running hte code i am using Script in Atom as i cannot make sense of using hte terminal (another frustration for a separate topic) but i have set up script to run in python 3 (which i have downloaded btw).

I am 99% sure its the f" which is tripping me up - every time i end the code line Atom seems to treat it as the start of the quote and insert a second set of quotes.

thanks

Ben

Right - thank you do much for everyone’s time. I have fixed it. After a bit of wrangling i managed to work out how to get my code to run using Python3 in Mac terminal.

It was 100% human error on my part - the script package in Atom is ok but the terminal works.

Apologies if i have wasted anyone’s time - thank you again.

Wishing you all the best

Ben

No worries. It’s good you cracked it. Have you check out the intro to the terminal / cli in the appendix?

It should help you out with basic terminal use and get you up to speed. It’s also covered in the preconditions for the course.

Ohhhh, you mean you type:

f"

Then it add on another ", then you type " again and sometimes you end up with:

f"""

Something like that? That’s called “smart quotes” and you should turn it off. It’s usually more harm than helpful and just makes typing the code more difficult, especially since you have to type the next " anyway so I don’t get what it’s helping with.

In the options look for “smart quotes” and that should also turn it off for () and [] and {} combos.

A free service run by Zed A. Shaw for learncodethehardway.org.