Last active
April 11, 2023 02:53
-
-
Save CalK16/ca475a1c52b3acd771a7c908f94a4354 to your computer and use it in GitHub Desktop.
an ATM machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BANK_ACCOUNT = "steven" | |
PASSWORD = "123456" | |
failed_attempts = 0 | |
balance = 1000 | |
def welcome(): | |
print("Welcome to my ATM machine!") | |
def get_bank_account(): | |
while True: | |
print("Please enter your bank account") | |
entered_bank_account = input() | |
if entered_bank_account != BANK_ACCOUNT: | |
print("bank account does not exists") | |
continue | |
return | |
def prompt_options(): | |
print("What can I help you? Enter the NUMBER") | |
print("1. withdraw") | |
print("2. check balance") | |
print("3. deposit") | |
print("4. change password") | |
print("5. exit") | |
def select_business(): | |
while True: | |
prompt_options() | |
try: | |
selection = int(input()) | |
except: | |
print("Error! please enter the NUMBER (1-5)") | |
continue | |
if 1 <= selection <= 5: | |
return selection | |
print("Error! please enter the NUMBER (1-5)") | |
def check_balance(): | |
print("Currently there are $", balance, "in your account") | |
while True: | |
welcome() | |
get_bank_account() | |
if failed_attempts >= 3: | |
print("Account is locked! exiting") | |
continue | |
while failed_attempts < 3: | |
print("Please enter password for ", BANK_ACCOUNT) | |
entered_password = input() | |
if entered_password != PASSWORD: | |
print("Password incorrect! Please try again") | |
failed_attempts += 1 | |
else: | |
entered_password = 0 | |
break | |
if failed_attempts >= 3: | |
print("Account is locked! exiting") | |
continue | |
print("Hi,", BANK_ACCOUNT) | |
while True: | |
selection = select_business() | |
if selection == 1: | |
check_balance() | |
while True: | |
print("How much would you like to withdraw?") | |
try: | |
amount = float(input()) | |
except: | |
print("Please enter numbers") | |
else: | |
if amount < 0: | |
print("You cannot withdraw less than 0 dollars, please try again") | |
continue | |
if amount > balance: | |
print("You don't have enough money to with draw! (", amount, ">", balance, "), please try again") | |
continue | |
balance -= amount | |
print("withdraw success! current balance: ", balance) | |
break | |
elif selection == 2: | |
check_balance() | |
elif selection == 3: | |
while True: | |
print("Please enter the money amount you want to deposit") | |
amount = input() | |
try: | |
amount = float(amount) | |
except: | |
print("Error! Please enter numbers") | |
else: | |
if amount <= 0: | |
print("Error! please enter amount that is more than 0 dollars") | |
continue | |
balance += amount | |
print("deposit success! current balance:", balance) | |
break | |
elif selection == 4: | |
print("Please enter a new password") | |
PASSWORD = input() | |
print("Password changed") | |
elif selection == 5: | |
print("Bye!") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment