Cannot work out the issue here

First of all,

Hello everyone I am new to programing and definitely new here. I am following an example from the book for Python 3 Page 50 exercise 5.

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 too 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, try to get it exactly right

total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

I cannot execute the code - it comes back with a syntax error:

File “example.py”, line 10
print(f"Let’s talk about {my_name}.")
^
SyntaxError: invalid syntax

Any idea why this is? I have searched Google and the only answer I could find is that F-String does not work in Executables, so I tried it right into the Python interpreter and still to no avail.

Thanks.

@Luke

check your quotation marks, you start the quote with one type then end with another
look carefully.
example:
my_name = 'Zed A. Shaw’

Jason

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 too 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, try to get it exactly right

total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

That still does not work if you meant the variable was in ’ quote and pulled up with ".

I just constantly get:

File “example.py”, line 10
print(f"Let’s talk about {my_name}.")
^
SyntaxError: invalid syntax

I just cannot continue or rest until I know what the heck it is.

@Luke

there is nothing wrong with the line in the error print('f"Let’s tal etc.
it’s the line before with incorrect speech marks that is throwing the above line out

my_hair = “Brown”
print(“Actually that’s not too heavy.”)

need correcting as they are not matching speech marks used elsewhere.

This code works for me

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 too 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, try to get it exactly right

total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

Your code does not even work for me at all, it is really annoying how I cannot even figure out why. I did think it was maybe using python 2 instead of 3 but the rules are the same for both.

please see: https://ibb.co/h1fpPw

Is there still something wrong in there? It still points to the same error, I literally cannot move on without knowing why haha I am one of those people.

@Luke

hmm looks like a world of pain using LPTHW3 with Python2, off the top of my head the print statements are different, I suspect the speech marks are handled differently, stricter in Python2

The code works for me on Python3, afraid Python2 must be the problem

I am actually using python3 via commandline I tried it in 2 and still the same error - this is incredible lol.

@Luke

if I copy my code back from this webpage and paste into VS code it works, if I paste the same code into notepad and save & run I now get UTF8 errors on the same line as you. if I retype the line, the error moves to the next line, there is some text formatting in the there that VS code is dealing with with raw editor is not.

I’ve just opened the code in VS code, it appears now not to like the apostrophes used, change these and try again
lines

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 too heavy.”)
print(f"He�s got {my_eyes} eyes and {my_hair} hair.")

I can’t replicate your fault exactly so I’m struggling to chase it down, computers eh!

I have python 3.5.2

I would use windows but I have not used that in over 10 years! Haha I run Linux mint and Ubuntu.

Hi @Luke, you may have 2 problems:

  1. You’re using Python 3.5 and need to use Python 3.6. That’s explained in the videos, every time I install it I use Python 3.6, and in every demonstration.

  2. I have no idea how, but you somehow have typographer’s style quotes on this line:

my_hair = “Brown”

See how your quotes on that line only have a slant to them? Weirdly even the slant is wrong, so you need to change it to this:

my_hair = "Brown"

See how those are straight quotes? I’m curious if you copy-pasted this line from the PDF? If you did, when did you download the PDF as that means I may have some stray bad quotes I have to hunt down.

@Luke
@zedshaw

aha can now replicate the fault, if I break out the mint laptop and use the code from my above post, it runs fine with python3.6

minty@minty-lp ~/Dropbox/python/lpthw $ python3.6 ex5text.py
Let’s talk about Zed A. Shaw.
He’s 74 inches tall.
He’s 180 pounds heavy.
Actually that’s not too heavy.
He’s got Blue eyes and Brown hair.
His teeth are usually White depending on the coffee.
If I add 35, 74, and 180 I get 289.

where as if I run with python 3.5 I get the error

minty@minty-lp ~/Dropbox/python/lpthw $ python3.5 ex5text.py
File “ex5text.py”, line 9
print(f"Let’s talk about {my_name}.")
^
SyntaxError: invalid syntax
minty@minty-lp ~/Dropbox/python/lpthw $

also why does this line have no remark symbol #:

this line is tricky, try to get it exactly right

got there in the end, upgrade to python 3.6 which from memory will a 'learning opportunity".

UPDATE just checked and looks like you can add python3.6 to the repo no compilation required, yippee, have not tried this but looks reasonable:
https://mintguide.org/other/794-python-3-6-install-latest-version-into-linux-mint.html

Nice, good job figuring it out. Also watch those quotes like I mentioned. You might have some kind of unicode setting or similar config in your text editor without realizing it.

Hi Luke,
You had different quote notations. I printed it out and the corrections.

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 too 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.")
total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

The notations where not matching each other. I’m only on ex 17 and I have trouble with others. I’m glad to find someone who’s on the same subject. I hope to be where you are, I’m having problems as well. I hope I’m doing the right things. All I can do is follow along, but I feel like there’s something missing on my part.

Thank You

Thanks for posting this question.

I’ve been having exactly the same problem for the last 24 hours but upgrading to Python 3.6 seems to have solved it. I am also using Linux Mint.

I can now stop tearing my hair out and get on with some more of the exercises…:slight_smile:

Hello all,

Thanks for the replies I did indeed update to 3.6 and it worked! I could not continue at all until I knew why.

Never the less must battle on - been eager to get through the exercises.

1 Like

Hi all, I also ran into this problem lately. I had Python 3.5.x.
I found that in 3.6, they changed how the f-string works. To be exact, the way we use it in the exercises was only implemented with 3.6 and not before.
https://cito.github.io/blog/f-strings/

In 3.5, i used e.g.
print(“Let’s talk about {}.”.format(my_name))
instead.

Hi @syzh, yes I used Python 3.6 and f-strings because we’re supposed to use the latest Python 3 and that’s the most recent. Also because f-strings a great.

Hi ZedShaw

I am using Python 3.6.5 and still getting this error for my code. Could you please advise?.

[******** lpthw]$ python ex5.py
File “ex5.py”, line 10
print(f"Let’s talk about {my_name}.")
^

my_name = ‘Zed A. Shaw’
my_age = 35 # It’s close to my real age
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 is {my_height} inches tall.")
print(f"He is {my_weight} pounds heavy.")
print(“Actually, that’s not too 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.")

total = my_age + my_height + my_weight

print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

I am using VI Editor and tried changing the single quotes in the variable to double quotes and still getting the same error.

my_name = “Zed A. Shaw”
my_age = 35 # It’s close to my real age
my_height = 74 #inches
my_weight = 180 #lbs
my_eyes = “Blue”
my_teeth = “White”
my_hair = “Brown”