Question 2
Back to Exercise
The program below stops with an error. Which statement correctly describes the problem?
class Product:
def __init__(self, name, price):
self.name = name
self.price = price
p = Product("Pen")
print(p.name)
- A It prints Pen
- B AttributeError: price
- C TypeError: __init__ requires price but only name was given; pass it or give price a default Correct
- D NameError
Correct Answer: Option C
Arguments to the class call go to __init__ and follow the same rules as a function call.
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!