F strings giving an parse error

I am using repl.it py with turtle
When using f strings on python with turtle, I call an f string with a random int as a variable
import random
damage = random.randint(0, 50)
print(f"Dragon caused {damage} damage")
it gives an parse error when running the code, any help?

Hello, @keztone, and welcome to the Python Forum!

The code that you have posted executes without any problem. When you received the error, was there any additional code in the file? There is nothing there involving turtle. If there was additional code, we will need to see it in order to provide effective help.

It works for me.

go to https://replit.com
😂
 import random
 damage = random.randint(0, 50)
 print(f"Dragon caused {damage} damage")
Dragon caused 11 damage

It will help if you copy and paste the exact error message you get, and
the exact line of code used.

Your code, combined with code from Python.org: turtle — Turtle graphics, runs just fine on repl.it and on own my MacBook Air.

Here is the combined code:

from turtle import *
import random
damage = random.randint(0, 50)
print(f"Dragon caused {damage} damage")
color('red', 'yellow')
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()

… and here is a picture of the output from repl.it:

So it is nether a problem with the portion of your code that you posted, nor a problem with turtle graphics on repl.it. Please check over all your code carefully, especially the lines immediately above the line where your parse error was detected.

Others have run your code without errors.

The only thing that occurs to me is maybe you are running a version of
Python too old to have f-strings? What version of Python are you running
this with?

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

repl.it does appear to be using a version of Python that recognizes f-strings. Though unlikely, is it possible that if repl.it has its Python turtle graphics implementation in several files, and that one of them contains a SyntaxError, it might get reported on the user’s screen? This is probably not the issue. Since we have not seen all of @keztone’s code, it does seem that the more likely explanation is an unclosed parenthesis or other problem on a line preceding the one that uses the f-string. So, we need to see that code.

EDITED on November 16, 2021 to revise a run-on sentence.