TypeError: 'str' object is not callable while trying to use python swampy
TypeError: 'str' object is not callable while trying to use python swampy
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)
这是调用字符串的尝试。结果的错误是 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()
您将 Turtle_1
创建为 Turtle
对象,这是正确的。但是,然后,在行 Turtle_1 = input('Please...')
中,您将 Turtle_1
设置为一个字符串,作为 input()
returns 一个字符串。当您随后尝试调用 color()
方法时,这不起作用,因为字符串没有这样的方法。另外,Turtles还有set_color()
设置颜色的方法,color
是属性,不能调用。
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)
这是调用字符串的尝试。结果的错误是 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()
您将 Turtle_1
创建为 Turtle
对象,这是正确的。但是,然后,在行 Turtle_1 = input('Please...')
中,您将 Turtle_1
设置为一个字符串,作为 input()
returns 一个字符串。当您随后尝试调用 color()
方法时,这不起作用,因为字符串没有这样的方法。另外,Turtles还有set_color()
设置颜色的方法,color
是属性,不能调用。