SHOW:
|
|
- or go back to the newest paste.
1 | def main_menu(): | |
2 | print("Select an option:") | |
3 | print("1. Deposit") | |
4 | print("2. Withdrawal") | |
5 | print("3. Check account balance") | |
6 | print("4. Exit") | |
7 | print("5. Show transaction history") | |
8 | ||
9 | def get_customer_choice(): | |
10 | return int(input("your choice is: ")) | |
11 | ||
12 | def get_amount(text): | |
13 | return float(input(text)) | |
14 | ||
15 | def show_account_balance(balance): | |
16 | print(f"The account balance is {balance}") | |
17 | ||
18 | ||
19 | def deposit(balance): | |
20 | deposit_amount = get_amount("How much would you like to deposit?") | |
21 | balance = balance + deposit_amount | |
22 | show_account_balance (balance) | |
23 | return balance | |
24 | ||
25 | ||
26 | def withdrawal(balance): | |
27 | withdrawal_amount = get_amount("How much would you like to withdraw?") | |
28 | if withdrawal_amount > balance: | |
29 | print("Operation failed, not enough funds on the account ") | |
30 | return balance | |
31 | else: | |
32 | balance -= withdrawal_amount | |
33 | print(f"The amount withdrawn {withdrawal_amount}") | |
34 | return balance | |
35 | ||
36 | ||
37 | ||
38 | def get_data(data): | |
39 | return input(f"Enter {data} number:") | |
40 | ||
41 | def check_data_validity(database, card, pin): | |
42 | for customer in database: | |
43 | if customer[0] == card: | |
44 | return customer[1] == pin | |
45 | return False | |
46 | ||
47 | ||
48 | def get_account_balance(database, card): | |
49 | for customer in database: | |
50 | if customer[0] == card: | |
51 | return customer[2] | |
52 | return 0 | |
53 | ||
54 | ||
55 | ||
56 | def update_customer_history(database, card, transaction): | |
57 | for customer in database: | |
58 | if customer[0] == card: | |
59 | customer[3].append(transaction) | |
60 | ||
61 | def show_customer_history(database, card): | |
62 | for customer in database: | |
63 | if customer[0] == card_provided: | |
64 | for i in range(len(customer[3])): | |
65 | print(f'{i+1}. {customer[3][i]}') | |
66 | ||
67 | #we write all the functions of our program above!!! | |
68 | choice = 0 | |
69 | balance = 0 | |
70 | #CARD = "0001" | |
71 | #PIN = "1234" | |
72 | CUSTOMERS = [ | |
73 | ["0001","1234",0,[] ], | |
74 | ["0002", "1111", 120,[]], | |
75 | ["0003", "3232", 1223.33,[]] | |
76 | ] | |
77 | #below is the main loop of the program | |
78 | card_provided = get_data("card") | |
79 | pin_provided = get_data("PIN") | |
80 | ||
81 | if check_data_validity(CUSTOMERS, card_provided, pin_provided): | |
82 | balance = get_account_balance(CUSTOMERS, card_provided) | |
83 | while choice != 4: | |
84 | main_menu() | |
85 | choice = get_customer_choice() | |
86 | if choice == 1: | |
87 | balance = deposit(balance) | |
88 | update_customer_history(CUSTOMERS, card_provided, "Deposit") | |
89 | pass | |
90 | elif choice == 2: | |
91 | balance = withdrawal(balance) | |
92 | update_customer_history(CUSTOMERS, card_provided, "Withdrawal") | |
93 | pass | |
94 | elif choice == 3: | |
95 | show_account_balance(balance) | |
96 | update_customer_history(CUSTOMERS, card_provided, "Show balance") | |
97 | pass | |
98 | elif choice == 4: | |
99 | print("Shutting down the ATM") | |
100 | pass | |
101 | elif choice == 5: | |
102 | show_customer_history(CUSTOMERS, card_provided) | |
103 | pass | |
104 | else: | |
105 | print("Invalid data") | |
106 | pass | |
107 | pass | |
108 | else: | |
109 | print("Login error") | |
110 | ||
111 | ||
112 | ||
113 |