Last answered:

16 Jan 2023

Posted on:

18 Nov 2022

0

SyntaxError: f-string: expecting '}'

Hello,

When using the f string on the Question 4, I keep getting this error message in Spyder: SyntaxError: f-string: expecting '}'

I have used your code exact as you have in the video, and it still produces the same error message:

user_input = (input('Please enter a number between 1 and 12:>>' ))

while (not user_input.isdigit()) or (int(user_input) < 1 or int(user_input) > 12):
    print('Must be an integer between 1 and 12')
    user_input = input('Please make a selection:>> ')
user_input = int(user_input)
print('============================')
print()
print(f'This is the {user_input} times table')
print()
for i in range(1,13):
    print(f'{i} x {user_input} = {i=user_input}')

Error: runfile('/Users/new-dawn/spyder-files/For-Loops.py', wdir='/Users/new-dawn/spyder-files')
  File "<unknown>", line 53
    print(f'{i} x {user_input} = {i=user_input}')
                                                ^
SyntaxError: f-string: expecting '}'

Appreciate your help.

Best Regards,

Justin

2 answers ( 0 marked as helpful)
Instructor
Posted on:

21 Nov 2022

0

Hye Justin,

Thank you for reaching out!

In the last print-function, substitute the last equal sign by a multiplication sign, that is

print(f'{i} x {user_input} = {i*user_input}')

This should solve the issue.

Kind regards,
365 Hristina

Posted on:

16 Jan 2023

0

Python is getting confused as you are using ' ' (single-quotes) for the f-string. The Python "SyntaxError: f-string: expecting '}'" occurs when we use single quotes inside of an f-string that was wrapped using single quotes. To solve the error, make sure to wrap your f-string in double quotes if it contains single quotes and vice versa.

Submit an answer