Skip to content

Commit 41e3118

Browse files
authored
added atm system program in python
1 parent b2fe390 commit 41e3118

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import random
2+
3+
4+
class Account:
5+
# Construct an Account object
6+
def __init__(self, id, balance=0, annualInterestRate=3.4):
7+
self.id = id
8+
self.balance = balance
9+
self.annualInterestRate = annualInterestRate
10+
11+
def getId(self):
12+
return self.id
13+
14+
def getBalance(self):
15+
return self.balance
16+
17+
def getAnnualInterestRate(self):
18+
return self.annualInterestRate
19+
20+
def getMonthlyInterestRate(self):
21+
return self.annualInterestRate / 12
22+
23+
def withdraw(self, amount):
24+
self.balance -= amount
25+
26+
def deposit(self, amount):
27+
self.balance += amount
28+
29+
def getMonthlyInterest(self):
30+
return self.balance * self.getMonthlyInterestRate()
31+
32+
33+
def main():
34+
# Creating accounts
35+
accounts = []
36+
for i in range(1000, 9999):
37+
account = Account(i, 0)
38+
accounts.append(account)
39+
40+
# ATM Processes
41+
42+
43+
while True:
44+
45+
# Reading id from user
46+
id = int(input("\nEnter account pin: "))
47+
48+
# Loop till id is valid
49+
while id < 1000 or id > 9999:
50+
id = int(input("\nInvalid Id.. Re-enter: "))
51+
52+
# Iterating over account session
53+
while True:
54+
55+
# Printing menu
56+
print("\n1 - View Balance \t 2 - Withdraw \t 3 - Deposit \t 4 - Exit ")
57+
58+
# Reading selection
59+
selection = int(input("\nEnter your selection: "))
60+
61+
# Getting account object
62+
for acc in accounts:
63+
# Comparing account id
64+
if acc.getId() == id:
65+
accountObj = acc
66+
break
67+
68+
# View Balance
69+
if selection == 1:
70+
# Printing balance
71+
print(accountObj.getBalance())
72+
73+
# Withdraw
74+
elif selection == 2:
75+
# Reading amount
76+
amt = float(input("\nEnter amount to withdraw: "))
77+
ver_withdraw = input("Is this the correct amount, Yes or No ? " + str(amt) + " ")
78+
79+
if ver_withdraw == "Yes":
80+
print("Verify withdraw")
81+
else:
82+
break
83+
84+
if amt < accountObj.getBalance():
85+
# Calling withdraw method
86+
accountObj.withdraw(amt)
87+
# Printing updated balance
88+
print("\nUpdated Balance: " + str(accountObj.getBalance()) + " n")
89+
else:
90+
print("\nYou're balance is less than withdrawl amount: " + str(accountObj.getBalance()) + " n")
91+
print("\nPlease make a deposit.");
92+
93+
# Deposit
94+
elif selection == 3:
95+
# Reading amount
96+
amt = float(input("\nEnter amount to deposit: "))
97+
ver_deposit = input("Is this the correct amount, Yes, or No ? " + str(amt) + " ")
98+
99+
if ver_deposit == "Yes":
100+
# Calling deposit method
101+
accountObj.deposit(amt);
102+
# Printing updated balance
103+
print("\nUpdated Balance: " + str(accountObj.getBalance()) + " n")
104+
else:
105+
break
106+
107+
elif selection == 4:
108+
print("nTransaction is now complete.")
109+
print("Transaction number: ", random.randint(10000, 1000000))
110+
print("Current Interest Rate: ", accountObj.annualInterestRate)
111+
print("Monthly Interest Rate: ", accountObj.annualInterestRate / 12)
112+
print("Thanks for choosing us as your bank")
113+
exit()
114+
115+
# Any other choice
116+
else:
117+
print("nThat's an invalid choice.")
118+
119+
# Main function
120+
main()

0 commit comments

Comments
 (0)