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.
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.
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.
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
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!
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.
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.
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".
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.
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.
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.
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}.")