Skip to content

Commit 1f8b02c

Browse files
committed
PublishSecond
1 parent 13e7f6e commit 1f8b02c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

02 - Constructor & __init__/README.md

Whitespace-only changes.

02 - Constructor & __init__/main.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Item:
2+
def __init__(self, name: str, price: float, quantity=0):
3+
# Run validations to the received arguments
4+
assert price >= 0, f"Price {price} is not greater than or equal to zero!"
5+
assert quantity >= 0, f"Quantity {quantity} is not greater or equal to zero!"
6+
7+
# Assign to self object
8+
self.name = name
9+
self.price = price
10+
self.quantity = quantity
11+
12+
def calculate_total_price(self):
13+
return self.price * self.quantity
14+
15+
item1 = Item("Phone", 100, 1)
16+
item2 = Item("Laptop", 1000, 3)
17+
18+
print(item1.calculate_total_price())
19+
print(item2.calculate_total_price())

0 commit comments

Comments
 (0)