-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathatm_simulation_beginner_github.py
More file actions
57 lines (53 loc) · 2.11 KB
/
atm_simulation_beginner_github.py
File metadata and controls
57 lines (53 loc) · 2.11 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
def atm_simulator():
"""
Simulates an ATM where you can check balance, deposit, and withdraw money.
Uses built-in functions like input(), sum(), and enumerate() for functionality.
"""
print("💳 Welcome to the Python ATM! 💳")
balance = 1000 # Starting balance
transactions = [] # Keep track of all transactions
while True:
print("\n🔸 What would you like to do?")
print("1. Check Balance 🏦")
print("2. Deposit Money 💰")
print("3. Withdraw Money 💸")
print("4. Transaction History 📜")
print("5. Exit 🚪")
# Get the user's choice
choice = input("Enter your choice (1-5): ").strip()
if choice == "1":
# Check balance
print(f"Your current balance is: ${balance:.2f}")
elif choice == "2":
# Deposit money
amount = float(input("Enter the amount to deposit: $"))
balance += amount
transactions.append(("Deposit", amount))
print(f"${amount:.2f} deposited successfully!")
elif choice == "3":
# Withdraw money
amount = float(input("Enter the amount to withdraw: $"))
if amount > balance:
print("❌ Insufficient funds!")
else:
balance -= amount
transactions.append(("Withdrawal", amount))
print(f"${amount:.2f} withdrawn successfully!")
elif choice == "4":
# Show transaction history
if not transactions:
print("No transactions yet!")
else:
print("\n📜 Transaction History 📜")
for i, (type_, amount) in enumerate(transactions, start=1):
print(f"{i}. {type_}: ${amount:.2f}")
elif choice == "5":
# Exit
print("Thank you for using the Python ATM. Goodbye! 👋")
break
else:
print("❌ Invalid choice. Please try again.")
def main():
atm_simulator()
if __name__ == "__main__":
main()