Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

TypeError: sequence item 0: expected str instance, type found

Hi, I can run the fine without the race_course function. At the moment it is throwing a type error, and I don't know why!

import random import time

class Horse: def init(self, name, ability): self.name = name self.ability = ability

def score(ability): roll = random.randint(1,6) if roll < ability: return True

def race_course(name, pos): lane = [Horse, '|', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '','', '', '', '', '', '', '', '', '_', '|'] lane.insert(pos, 'H') lane_joined = ''.join(lane) return lane_joined

H_1 = Horse('Colin', 3) H_2 = Horse('Clive', 3)

H_1_pos = 2 H_2_pos = 2

x = True

while x: if score(H_1.ability) == True: H_1_pos += 1

if score(H_2.ability) == True:
    H_2_pos += 1

print('\n' * 20)
print(race_course(H_1.name, H_1_pos))

time.sleep(.25)

1 Answer

Steven Parker
Steven Parker
243,173 Points

Can you provide a link to the course page you are working with?
Also, always use Markdown formatting when posting code (especially Python!).