Python 3 Ex5 Quotation mark syntax error

I’ve tried everything: changed quotation marks, spacing, commented out line by line, still can’t figure out what’s wrong

File “”, line 9
print(f “Let’s talk about {my_name}.”)
____________________________ ^
SyntaxError: Invalid Syntax


my_name= “Zed A.Shaw”
my_age= 35#not a lie
my_height= 74#inches
my_weight= 180#lbs
my_eyes= “Blue”
my_teeth= “White”
my_hair= “Brown”

print(f “Let’s talk about {my_name}.”)
print(f “He’s {my_height} inches tall.”)
print(f “He’s {my_weight} pounds heavy.”)
print(“Actually that’s not oo heavy.”)
print(f “He’s got {my_eyes} eyes and {my_hair} hair”.)
print(f “His teeth are usually {my_teeth} depending on the coffee”.)

#this line is tricky, get it exactly right
print(f"if I add {my_age}, {my_height}, and {my_weight} I get {total}.")

After fixing some spacing issues I finally managed to get it running by typing it out in a different file and copying and pasting, I then had to fix lines 7 and 14 the same way, Atom wasn’t auto-completing my quotes, and I think that was the problem. Any ideas on how to fix this it still randomly will not complete the quotes forcing me to open another file.

I notice this only happens when I type “f” before I type the quotations, and if I try to complete the quotation manually - I get a syntax error.

The updated code:

my_name = “Zed A.Shaw”
my_age = 35#not a lie
my_height = 74#inches
my_weight = 180#lbs
my_eyes= “Blue”
my_teeth = “White”
my_hair = “Brown”

print(f"Let’s talk about {my_name}.")
print(f"He’s {my_height} inches tall.")
print(f"He’s {my_weight} pounds heavy.")
print(“Actually that’s not oo heavy.”)
print(f"He’s got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee")

#this line is tricky, get it exactly right
print(f"if I add {my_age}, {my_height}, and {my_weight} I get {total}.")
“His teeth are usually {my_teeth} depending on the coffee”

1 Like

Be carefull with the quotation marks. There are some typographic quoatation marks like the one used in books and newspapers and the ‘pure’ quoatation marks. The only one Python will understand.

# typographic quotation marks  “ ” 
my_hair = “Brown” # this will not work

# technical quotation marks " "
print(f"Let’s talk about {my_name}.") # this will work

@DidierCH I am not sure that is true. It’s perfectly ok to interchange double and single-quotes on strings. Sometimes it’s easier that dealing with lots of escaped characters. For example:

my_hair = 'It\'s brown and it\'s not like Zed\'s hair'

It’s easier to use:

my_hair = "It's brown and it's not like Zed's hair"

Both examples are string literals and equal to each other.

The use of format strings is different as there is specific syntax required for the string interpolation, therefore must use double-quotes.

(f"some {string} injected")

I know in some languages (like Ruby), the use of single-quotes is quicker to process than double-quotes because the language hits a single quote and therefore knows there is no processing of things like the interpolation so doesn’t look ahead (lame non-tech description…)

As @jian pointed out (finding his own error - cool!) was the space between the format-string identifier and the actual quotation marks. That was all.

I’ve seen what @DidierCH is talking about when my keyboard input was wrong. There are different " . International keyboard settings have a different one that is slightly slanted, and python will not recognize it.
Two different double quotes, one set slanted on international key bindings, one not.

1 Like

Ah I see now, thanks @nellietobey . Sorry @DidierCH I misread that response completely in my British-keyboard arrogance!

(I was thinking - whats Didier going on about with those literals…) Proof that attention to detail is really important! :blush:

1 Like

Doesn’t matter @gpkesley :slight_smile: it’s not easy to see with that font-style and font-size used on this site. You need trained eyes in typography to see the difference in the example of @jian above.
Here is a good blog post about the topic:

This forum here will convert every quotation mark that is not wrapped as code in their typographically correct form. So be careful to paste your code in “wrappers” like the backtics ``` or the [code] brackets.

1 Like