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 trialAntonia Bruno
4,283 PointsPython inheritance, why is it throwing a SyntaxError when I run the program? [Solved]
import random
class Character:
def __init__(self, name, **kwargs):
self.name = name
for key, value in kwargs.items():
setattr(self, key, value)
class Thief(Character):
sneaky = True
def __init__(self, name, sneaky=True, **kwargs):
super().__init__(name, **kwargs)
self.sneaky = sneaky
def pickpocket(self):
return self.sneaky and bool(random.randint(0, 1))
def hide(self, light_level):
return self.sneaky and light_level < 10
source /Users/antonia/anaconda3/bin/activate
conda activate base
(base) antonias-MacBook-Pro:objectO antonia$ source /Users/antonia/anaconda3/bin/activate
(base) antonias-MacBook-Pro:objectO antonia$ conda activate base
(base) antonias-MacBook-Pro:objectO antonia$ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from character import Thief
>>> antonia = ("Antonia", sneaky=False, clever=True)
File "<stdin>", line 1
antonia = ("Antonia", sneaky=False, clever=True)
^
SyntaxError: invalid syntax
>>>
1 Answer
Antonia Bruno
4,283 PointsActually fixed that problem forgot to add Theif before defined the attributes. But now it's giving me this error
SyntaxError: invalid syntax
>>> antonia = Thief("Antonia", sneaky=False, clever=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "character.py", line 14, in __init__
super().__init__(name, **kwargs)
TypeError: super() takes at least 1 argument (0 given)
>>>