Ex5.py Error Keeps Happening

So I went through exercise 5 and I am still getting a syntax error even though it seems to be the same as what Zed wrote in the book. I checked it many times, but I still can’t find the error. Can anybody see what I did wrong? example%205%20picture

Hi @evancruz1

This f string in the print function only works in Python 3.6 or higher.
If you dont know which version you have installed you can check which:

python3 - -version

If you have this you can run your code with:

python3 ex5.py

Hopefully there is just this that gave you the error.

Hi @evancruz1

Now you got two threads about the same problem:
I saw you replied on the other one:
Got an error in exercise 5 and need to know what it is

There seems to be some other kind of problem that gives you this error.
But to be able to give you help we need to see all of your code.
Not just the line that seems to be the reason for error.

Please put it in like this:
Copy from your pc…

Paste it in here..

Here’s the code:

Do you have your keyboard set to international? Sometimes the keyboard setting changes the quotes to a different kind, and Python can’t recognize them as quotes.

This happens a lot.

Hey, you’re not mixing double quotes and single qoutes. Always look at the variables contained in the line error too.
Your name is in double quotes. So is the f-string. One or the other has to be single quotes.
“My name is ‘Nellie’.” Instead of:
“My name is “Nellie”.”

Hi @evancruz1 is this resolved? Did you figure out the solution?

Hi @zedshaw! I’m here having the same issue. I have Python 3.6, then I installed the lastest version (python 3.7) and still the same. Could you please give me a clue, I’m gettin crazy hehe. Many thanks

The error:

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

Here is my code:

my_name = ‘Zed A. Shaw’
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 # lbs
my_eyes = ‘Blue’
my_theeth = ‘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 theeth are usually {my_theeth} 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}.")

Hi and welcome to the forum @Javulja

You seem to have used tick and backtick around strings.
There must be quotes or double quotes only.
When this is corrected your code should run perfectly.

1 Like