yusuf ziya ozgul
yusuf ziya ozgul

Reputation: 13

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)

Upvotes: -2

Views: 431

Answers (2)

Nobozarb
Nobozarb

Reputation: 344

You created Turtle_1 as a Turtle object, which is correct. Then, however, with the line Turtle_1 = input('Please...'), you set Turtle_1 to a string, as input() returns a string. When you then attempted to call the color() method, this did not work, as strings have no such method. In addition, Turtles also have the set_color() method for setting the color, and color is an attribute and cannot be called.

Upvotes: 1

Dan D.
Dan D.

Reputation: 74645

This is an attempt to call a string. The error that results is TypeError: 'str' object is not callable.

Turtle_1.color(T1_color)

color is a string property of Turtle. To set the color, use:

Turtle_1.set_color(T1_color)

Which is the same as:

Turtle_1.color = T1_color
Turtle_1.redraw()

Upvotes: 1

Related Questions