-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM_interface.py
More file actions
70 lines (56 loc) · 1.97 KB
/
ATM_interface.py
File metadata and controls
70 lines (56 loc) · 1.97 KB
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
class BankAccount:
def __init__(self, initial_balance):
self.balance = initial_balance
def get_balance(self):
return self.balance
def deposit(self, amount):
if amount > 0:
self.balance += amount
print(f"Deposit successful. New balance: ${self.balance:.2f}")
else:
print("Invalid deposit amount.")
def withdraw(self, amount):
if amount > 0 and amount <= self.balance:
self.balance -= amount
print(f"Withdrawal successful. New balance: ${self.balance:.2f}")
return True
else:
print("Insufficient balance or invalid withdrawal amount.")
return False
class ATM:
def __init__(self, account):
self.user_account = account
def display_menu(self):
print("\nATM Menu:")
print("1. Check Balance")
print("2. Deposit Funds")
print("3. Withdraw Funds")
print("4. Exit")
def run(self):
choice = 0
while choice != 4:
self.display_menu()
choice = int(input("Enter your choice (1-4): "))
if choice == 1:
self.check_balance()
elif choice == 2:
self.deposit_funds()
elif choice == 3:
self.withdraw_funds()
elif choice == 4:
print("Thank you for using the ATM!")
else:
print("Invalid choice. Please enter a valid option.")
def check_balance(self):
balance = self.user_account.get_balance()
print(f"Your account balance: ${balance:.2f}")
def deposit_funds(self):
amount = float(input("Enter the deposit amount: $"))
self.user_account.deposit(amount)
def withdraw_funds(self):
amount = float(input("Enter the withdrawal amount: $"))
self.user_account.withdraw(amount)
if __name__ == "__main__":
user_account = BankAccount(0)
atm = ATM(user_account)
atm.run()