Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main_menu():
- print("Select an option:")
- print("1. Deposit")
- print("2. Withdrawal")
- print("3. Check account balance")
- print("4. Exit")
- print("5. Show transaction history")
- def get_customer_choice():
- return int(input("your choice is: "))
- def get_amount(text):
- return float(input(text))
- def show_account_balance(balance):
- print(f"The account balance is {balance}")
- def deposit(balance):
- deposit_amount = get_amount("How much would you like to deposit?")
- balance = balance + deposit_amount
- show_account_balance (balance)
- return balance
- def withdrawal(balance):
- withdrawal_amount = get_amount("How much would you like to withdraw?")
- if withdrawal_amount > balance:
- print("Operation failed, not enough funds on the account ")
- return balance
- else:
- balance -= withdrawal_amount
- print(f"The amount withdrawn {withdrawal_amount}")
- return balance
- def get_data(data):
- return input(f"Enter {data} number:")
- def check_data_validity(database, card, pin):
- for customer in database:
- if customer[0] == card:
- return customer[1] == pin
- return False
- def get_account_balance(database, card):
- for customer in database:
- if customer[0] == card:
- return customer[2]
- return 0
- def update_customer_history(database, card, transaction):
- for customer in database:
- if customer[0] == card:
- customer[3].append(transaction)
- def show_customer_history(database, card):
- for customer in database:
- if customer[0] == card_provided:
- for i in range(len(customer[3])):
- print(f'{i+1}. {customer[3][i]}')
- #we write all the functions of our program above!!!
- choice = 0
- balance = 0
- #CARD = "0001"
- #PIN = "1234"
- CUSTOMERS = [
- ["0001","1234",0,[] ],
- ["0002", "1111", 120,[]],
- ["0003", "3232", 1223.33,[]]
- ]
- #below is the main loop of the program
- card_provided = get_data("card")
- pin_provided = get_data("PIN")
- if check_data_validity(CUSTOMERS, card_provided, pin_provided):
- balance = get_account_balance(CUSTOMERS, card_provided)
- while choice != 4:
- main_menu()
- choice = get_customer_choice()
- if choice == 1:
- balance = deposit(balance)
- update_customer_history(CUSTOMERS, card_provided, "Deposit")
- pass
- elif choice == 2:
- balance = withdrawal(balance)
- update_customer_history(CUSTOMERS, card_provided, "Withdrawal")
- pass
- elif choice == 3:
- show_account_balance(balance)
- update_customer_history(CUSTOMERS, card_provided, "Show balance")
- pass
- elif choice == 4:
- print("Shutting down the ATM")
- pass
- elif choice == 5:
- show_customer_history(CUSTOMERS, card_provided)
- pass
- else:
- print("Invalid data")
- pass
- pass
- else:
- print("Login error")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement