我做了一个python程序,我不知道为什么它不工作。
我试过这个代码:
import turtle
screen=turtle.Screen()
opened_door="C:\Users\Roby&Gabry\Desktop\Monty Hall Paradox\opened_door.gif"
closed_door="C:\Users\Roby&Gabry\Desktop\Monty Hall Paradox\closed_door.gif"
screen.addshape(opened_door)
screen.addshape(closed_door)
t=turtle.Turtle()
t.shape(closed_door)
但每次我运行程序它都给我这样的错误:
File "c:\Users\Roby&Gabry\Desktop\Monty Hall Paradox\Monty Hall.py", line 3
opened_door="C:\Users\Roby&Gabry\Desktop\Monty Hall Paradox\opened_door.gif"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
错误在哪里?
1条答案
按热度按时间yftpprvb1#
文件路径包含反斜杠,这是Python中的转义字符,要绕过这个问题,可以在字符串前面加上
r
: