Issue
In a Jupyter cell, I have this class:
class Shirt:
def __init__(self, shirt_color, shirt_size, shirt_style, shirt_price):
self.color = shirt_color
self.size = shirt_size
self.style = shirt_style
self.price = shirt_price
def change_price(self, new_price):
self.price = new_price
def discount(self, discount):
return self.price * (1 - discount)
And when I do this:
import Shirt as shirt
shirt.color = 'red'
shirt.size = 'S'
shirt.style = 'long-sleeve'
shirt.price = 25
I get this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-d95b669ecd57> in <module>()
----> 5 import Shirt as shirt
6
7 shirt.color = 'red'
ModuleNotFoundError: No module named 'Shirt'
I am running the cell that declares the class Shirt so I don't know why its not recognizing it.
Solution
That's not how you create an object. You must do
shirt = Shirt('red', 'S', 'long-sleeve', 25)
Answered By - enzo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.