-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
70 lines (66 loc) · 2.7 KB
/
cli.py
File metadata and controls
70 lines (66 loc) · 2.7 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
from auth import create_account, verify_pin
from operations import deposit, export_history, withdraw, view_history
from reporting import generate_report
from logger import setup_logger
setup_logger()
def main():
print("Welcome to Titan ATM System (Modular Day 6)")
while True:
print("\nMain Menu:")
print("1. Create Account")
print("2. Login")
print("3. Generate System Report")
print("4. Exit")
print("5. Export History")
choice = input("Choose option: ")
if choice == "1":
name = input("Name: ")
pin = input("PIN (digits): ")
initial = input("Initial deposit (optional): ") or "0"
acc = create_account(name, pin, float(initial))
print(f"Account created: {acc}")
elif choice == "2":
acc = input("Account number: ")
pin = input("PIN: ")
if verify_pin(acc, pin):
print("Login success.")
while True:
print("\n1. Deposit\n2. Withdraw\n3. View History\n4. Logout\n5. Export History")
c = input("Choice: ")
if c == "1":
amt = float(input("Amount: "))
try:
new_bal = deposit(acc, amt)
if isinstance(new_bal, (int, float)):
print(f"New balance: ${float(new_bal):.2f}")
else:
print(new_bal) # handle textual response from operations
except Exception as e:
print(f"Error: {e}")
elif c == "2":
amt = float(input("Amount: "))
try:
new_bal = withdraw(acc, amt)
if isinstance(new_bal, (int, float)):
print(f"New balance: ${float(new_bal):.2f}")
else:
print(new_bal) # handle textual response from operations
except Exception as e:
print(f"Error: {e}")
elif c == "3":
print(view_history(acc))
elif c == "4":
break
elif c == "5":
export_history(acc)
else:
print("Invalid option.")
else:
print("Invalid credentials.")
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid option.")
if __name__ == "__main__":
main()