Skip to content

Commit 83dc8c7

Browse files
committed
Implement str and immutability on coins
1 parent f2c34de commit 83dc8c7

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

coins.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,40 @@
33
"""
44
from dataclasses import dataclass
55

6+
@dataclass(frozen=True)
7+
class Coin:
8+
value: int
9+
label: str
10+
11+
def __str__(self):
12+
return self.label
13+
614

715
@dataclass(frozen=True)
8-
class Nickel:
16+
class Nickel(Coin):
917
value: int = 5
18+
label: str = '5¢'
1019

1120

1221
@dataclass(frozen=True)
13-
class Dime:
22+
class Dime(Coin):
1423
value: int = 10
24+
label: str = '10¢'
1525

1626

1727
@dataclass(frozen=True)
18-
class Quarter:
28+
class Quarter(Coin):
1929
value: int = 25
30+
label: str = '25¢'
2031

2132

2233
@dataclass(frozen=True)
23-
class Loonie:
34+
class Loonie(Coin):
2435
value: int = 100
36+
label: str = '$1'
2537

2638

2739
@dataclass(frozen=True)
28-
class Toonie:
40+
class Toonie(Coin):
2941
value: int = 200
42+
label: str = '$2'

0 commit comments

Comments
 (0)