-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM simulator
57 lines (50 loc) · 1.87 KB
/
ATM simulator
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
class VirtualATM:
def __init__(self, balance=1000): # Default balance set to 1000
self.balance = balance
def check_balance(self):
print(f"\nYour current balance is: ₹{self.balance}")
def deposit(self):
try:
amount = float(input("\nEnter amount to deposit: ₹"))
if amount > 0:
self.balance += amount
print(f"₹{amount} deposited successfully!")
else:
print("Invalid amount! Please enter a positive value.")
except ValueError:
print("Invalid input! Please enter a numeric value.")
def withdraw(self):
try:
amount = float(input("\nEnter amount to withdraw: ₹"))
if amount > self.balance:
print("Insufficient balance!")
elif amount > 0:
self.balance -= amount
print(f"₹{amount} withdrawn successfully!")
else:
print("Invalid amount! Please enter a positive value.")
except ValueError:
print("Invalid input! Please enter a numeric value.")
def run(self):
while True:
print("\n===== Virtual ATM =====")
print("1. Check Balance")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Exit")
choice = input("Enter your choice (1/2/3/4): ")
if choice == '1':
self.check_balance()
elif choice == '2':
self.deposit()
elif choice == '3':
self.withdraw()
elif choice == '4':
print("Thank you for using Virtual ATM. Goodbye!")
break
else:
print("Invalid choice! Please enter a valid option.")
# Run the ATM Program
if __name__ == "__main__":
atm = VirtualATM()
atm.run()