-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathEX12.3.py
74 lines (57 loc) · 2.36 KB
/
EX12.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
# 12.3 (Game: ATM machine) Use the Account class created in Exercise 7.3 to simulate
# an ATM machine. Create ten accounts in a list with the ids 0, 1, ..., 9, and an initial
# balance of $100. The system prompts the user to enter an id. If the id is entered
# incorrectly, ask the user to enter a correct id. Once an id is accepted, the main
# menu is displayed as shown in the sample run. You can enter a choice of 1 for
# viewing the current balance, 2 for withdrawing money, 3 for depositing money,
# and 4 for exiting the main menu. Once you exit, the system will prompt for an id
# again. So, once the system starts, it won’t stop.
class Account:
def __init__(self, id=0, balance=100, annualIntersetRate=0):
self.__id = id
self.__balance = balance
self.__annualIntersetRate = annualIntersetRate
def getId(self):
return self.__id
def getBalance(self):
return self.__balance
def getAnnualIntersetRate(self):
return self.__annualIntersetRate
def setId(self, id):
self.__id = id
def setBalance(self, balance):
self.__balance = balance
def setAnnualIntersetRate(self, annualIntersetRate):
self.__annualIntersetRate = annualIntersetRate
def getMonthlyInterestRate(self):
return (self.__annualIntersetRate / 12) / 100
def getMonthlyInterest(self):
return self.__balance * self.getMonthlyInterestRate()
def deposit(self, balance):
self.__balance += balance
def withdraw(self, amount):
self.__balance -= amount
def main():
accounts = []
for i in range(10):
ac = Account(i)
accounts.append(ac)
id = eval(input("Enter an account id: "))
while (True):
if 0 <= id <= 9:
print("Main menu")
print("1: check balance\n2: withdraw\n3: deposit\n4: exit")
choice = int(input(""))
if choice == 1:
print("The balance is", accounts[id].getBalance(),"\n")
elif choice == 2:
amount = eval(input("Enter an amount to withdraw: \n"))
accounts[id].withdraw(amount)
elif choice == 3:
amount = eval(input("Enter an amount to deposit: \n"))
accounts[id].deposit(amount)
elif choice == 4:
break
else:
print("Enter a correct ID")
main()