-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoins.py
114 lines (84 loc) · 2.84 KB
/
coins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import random
#Super Class Coin
class Coin:
def __init__(self, rare =False, clean = True, heads = True, **kwargs):
for key,value in kwargs.items():
setattr(self,key,value)
self.rare=rare
self.is_clean=clean
self.heads=heads
if self.rare:
self.value=self.original_value*1.25
else:
self.value=self.original_value
if self.is_clean:
self.colour = self.clean_colour
else:
self.colour = self.rusty_colour
def rust(self):
self.colour=self.rusty_colour
def clean(self):
self.colour=self.clean_colour
def flip(self):
self.heads=random.choice([True, False])
def __str__(self):
if self.original_value>=1.00:
return "£{}Coin".format(int(self.original_value))
else:
return "{}p Coin".format(int(self.original_value*100))
def __del__(self):
print("Coin Spent!")
#Objects of the Class Coin
class One_Pence(Coin):
def __init__(self):
data = {"original_value":0.01,
"clean_colour":"bronze",
"rusty_colour":"brownish",
"num_edges" : 1,
"diameter": 20.3,
"thickness": 1.52,
"mass":3.56,
}
super().__init__(**data)
class Two_Pence(Coin):
def __init__(self):
data = {"original_value":0.02,
"clean_colour":"bronze",
"rusty_colour":"brownish",
"num_edges" : 1,
"diameter": 25.9,
"thickness": 1.85,
"mass":7.12,
}
super().__init__(**data)
class Five_Pence(Coin):
def __init__(self):
data = {"original_value":0.05,
"clean_colour":"silver",
"rusty_colour": None,
"num_edges" : 1,
"diameter": 18.0,
"thickness": 1.77,
"mass":3.25,
}
super().__init__(**data)
def rust(self):
self.colour = self.rusty_colour
def clean(self):
self.colour = self.clean_colour
class One_Pound(Coin):
def __init__(self):
data = {"original_value":1.00,
"clean_colour":"Gold",
"rusty_colour":"greenish",
"num_edges" : 1,
"diameter": 22.5,
"thickness": 3.15,
"mass":9.5,
}
super().__init__(**data)
coins = [One_Pound(),Five_Pence(),One_Pence(),Two_Pence()]
for coin in coins:
arguments=[coin, coin.colour, coin.value, coin.diameter, coin.thickness,coin.num_edges, coin.mass]
string="{} - Colour: {}, Value: {}, Diameter(mm): {}, Thickness(mm): {}, Edges: {}, Weigth: {}".format(*arguments)
print(string)