Build a ShopItem Class
Python
15 pts
Build a ShopItem Class
Create a class called ShopItem:
__init__takesnameandpriceand stores them asself.nameandself.price.- It also sets
self.in_stock = Truefor every new item (not a parameter).
Then create item = ShopItem("Bread", 10) and print:
Bread costs 10 Nakfa
Checklist
- Define a class called
ShopItemwhose__init__stores thenameandpriceit receives. - Give every new item the attribute
in_stockwith the valueTrue. - Create
item = ShopItem("Bread", 10)and print the sentence.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
