import turtle as t
color = ['green','red','blue']
r = ['20','50','60']
for i in range(3):
t.pu()
t.goto(0,-r[i])
t.pd()
t.pencolor(color[i])
t.circle(r[i])
t.done()
File "C:\pycharm\武球王.py", line 7, in
t.goto(0,-r[i])
TypeError: bad operand type for unary -: 'str'
我尝试过将减号去掉,但是没用,依旧报错
正确运行
import turtle as t
color = ['green','red','blue']
r = ['20','50','60']
for i in range(3):
t.pu()
t.goto(0,-eval(r[i]))
t.pd()
t.pencolor(color[i])
t.circle(r[i])
t.done()
或者:
import turtle as t
color = ['green','red','blue']
r = [20,50,60]
for i in range(3):
t.pu()
t.goto(0,-r[i])
t.pd()
t.pencolor(color[i])
t.circle(r[i])
t.done()