-
Notifications
You must be signed in to change notification settings - Fork 1
/
10.3.py
94 lines (70 loc) · 2.37 KB
/
10.3.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
"""
COMP.CS.100 Week Chapter
Name: Shamsur Raza Chowdhury <shamsurraza.chowdhury@tuni.fi>
Student Number: 050359798
This program
"""
class Person:
"""
This class models a person with a simple electronic wallet.
"""
def __init__(self, name, initial_money,address):
"""
A person object is initialized with the name and
the initial amount of money in the wallet.
:param name: str, the name of the person whose
spending the object is following.
:param initial_money: float, how much money will
there be in the wallet at the point of creation.
"""
self.__name = name
self.__money = initial_money
self.__address= address
def printout(self):
"""
When a person's data is needed to be printed on
screen this method will handle it. Also good
for debugging and testing purposes.
"""
print("—" * 25)
print("Name: ", self.__name)
print("Wealth: ", self.__money)
print("Address:", self.__address)
def add_money(self, amount):
"""
It is possible to add money in the electronic wallet.
:param amount: float, the amount of money added.
:return: True if operation successfull, False otherwise.
"""
if amount < 0.0:
return False
else:
self.__money += amount
return True
def make_payment(self, price):
"""
When making a payment, money needs to be
deducted from the person's wallet.
:param price: float, the price of the purchase
i.e. how much money to deduct from the wallet.
"""
if price < 0.0:
print("The price can't be negative.")
elif price > self.__money:
print("You can't afford that.")
else:
self.__money -= price
def move(self, newAddress):
self.__address= newAddress
def main():
# Let's create an object of type Person, name it denzil,
# and use to spy on Prof. Dexter's spending.
denzil = Person("Denzil Dexter", 100.00, "320 Memorial Dr.")
# State of Denzil
denzil.printout()
# Denzil moves out of a dormitory to a place of his own.
denzil.move("20 Chestnut St.")
# Where's Denzil after the move.
denzil.printout()
if __name__ == "__main__":
main()