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 trialCallum Anderson
Data Analysis Techdegree Student 10,200 PointsMissing Argument Error on video circle.py
followed through with video tutorial and must be oblivious to a wrong input but can't find it. Error reads ' TypeError: init() missing 1 required positional argument 'diameter' ' Code Below.
class Circle: def init(self, diameter): self.diameter = diameter
@property
def radius(self):
return self.diameter / 2
@radius.setter
def radius(self, radius):
self.diameter = radius * 2
small = Circle() print(small.diameter) print(small.radius) small.radius = 10 print(small.diameter)
1 Answer
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Callum,
class Circle:
def __init__(self, diameter): # <==== "HERE" | 1. init is missing the double underscores 2. diameter is required
self.diameter = diameter
@property
def radius(self):
return self.diameter / 2
@radius.setter
def radius(self, radius):
self.diameter = radius * 2
small = Circle() # <==== "HERE" | 1. A value needs to be passed in here to fulfill the diameter parameter
print(small.diameter)
print(small.radius)
small.radius = 10
print(small.diameter)
I've left some notes for you within the comments of the code above, but essentially what's happening is that because you're not passing an argument to the instance of the Circle() class that you're storing in small, the Circle object isn't able to initiate it's diameter value to anything. If you don't want to have to always pass in an argument (ie. if you want to make diameter an optional parameter), then you'll need to set up the Circle class definition to supply a default value for diameter, which would look something like this:
class Circle:
def __init__(self, diameter=15):
self.diameter = diameter
Hope that helps. Nice work so far!