Question 4
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
class Circle:
def __init__(self, radius):
self.radius = radius
def area(self):
return 3.14 * radius ** 2
print(Circle(2).area())
- A NameError: inside a method, attributes must be accessed through self – write self.radius Correct
- B It prints 12.56
- C AttributeError
- D TypeError
Correct Answer: Option A
Unlike Java or C++, Python never looks up attributes implicitly.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!