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

Uria Levi
PLUS
Uria Levi
Courses Plus Student 1,760 Points

Python OOP help(solved)

Hello everyone,

I made some code inspired by Kenneth (almost the same code as he does). When I try to run the code I get an error but I can't understand the problem.

I don't know how to copy as VSC mode so I will just copy-paste:

File #1 "character.py"

class Character:

def __init__(self,name="",*args, **kwargs):
    if not name:
        raise ValueError("'Name' is required!")
    self.name = name

    for key, value in kwargs.items():
        setattr(self, key, value)

---------------------------------------------------------------------

File #2"newbie.py"

import random

from attributes_newbie import Fast, Agile from characters import Character

class Newbie(Character, Agile, Fast): def fall(self): return self.fast and random.randint(0,1)

---------------------------------------------------------------------

File #3"attributes_newbie.py"

import random

class Fast: fast = True

def __init__(self, fast=True, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fast = fast

def fastest(self, speed):
    return self.fast and speed > 5

class Agile: def init(self, agile=True, *args, **kwargs): super().init(*args, **kwargs) self.agile = agile

def block(self):
    return self.agile and random.randint(0,1)

---------------------------------------------------------------------

file #4 "play.py"

from newbie import Newbie

Me = Newbie(name="Me") print(Me.agile) print(me.fast)

------------------------------------------------------------------------------------------------------------------------------------------

The error I get: File "Game/play.py", line 1, in <module>
from newbie import Newbie
File "/home/treehouse/workspace/Game/newbie.py", line 3, in <module>
from attributes_newbie import Fast, Agile
File "/home/treehouse/workspace/Game/attributes_newbie.py", line 19
return self.agile and random.randint(0,1)

Edit:

I forgot to add bool line 19 file3, & line 8 file 2

I receive now a tab error:

Traceback (most recent call last): File "c:/Users/ulevi/Desktop/Py Game/play.py", line 1, in <module> from newbie import Newbie File "c:\Users\ulevi\Desktop\Py Game\newbie.py", line 3, in <module> from attributes_newbie import Fast, Agile File "c:\Users\ulevi\Desktop\Py Game\attributes_newbie.py", line 19 return self.agile and bool(random.randint(0,1)) ^ TabError: inconsistent use of tabs and spaces in indentation

Edit 2:

I've found a few type errors I made in the code because I changed it a lot during coding. and I've found a solution to it - I had to change some code and it's running smooth.

1 Answer

Steven Parker
Steven Parker
231,269 Points

Congrats on resolving your own issue! :+1: