-2
from swampy.TurtleWorld import *
import random

world = TurtleWorld()
Turtle_1 = Turtle()

print('*****Welcome to Sehir Minesweeper*****')
print('-----First Turtle-----')

Turtle_1 = input('Please type the name of the first Turtle:')

print('Turtle 1 is' +' ' + Turtle_1)

T1_color = input('Please choose turtle color for' + ' ' + Turtle_1 +' '+'(red, blue or green):')

Turtle_1.color(T1_color)
4

2 回答 2

1

这是调用字符串的尝试。结果的错误是TypeError: 'str' object is not callable

Turtle_1.color(T1_color)

color是 的字符串属性Turtle。要设置颜色,请使用:

Turtle_1.set_color(T1_color)

这与以下内容相同:

Turtle_1.color = T1_color
Turtle_1.redraw()
于 2019-11-10T18:30:51.993 回答
1

您创建Turtle_1Turtle对象,这是正确的。但是,然后,使用 line Turtle_1 = input('Please...'),您设置Turtle_1为一个字符串,因为input()返回一个字符串。然后当您尝试调用该color()方法时,这不起作用,因为字符串没有这样的方法。另外,Turtles 也有set_color()设置颜色的方法,color是属性,不能调用。

于 2019-11-10T18:40:45.203 回答