In: Computer Science
Using python, produce code that mimics some ATM transactions:
a. A welcome message must be displayed initially reflecting the appropriate time of day (for example: Good Night, Welcome to Sussex Bank).
b. Assume the user’s account balance is $5375.27.
c. Allow the user to enter a pin number that does not have to be validated: def atm_login(): pin_number = input("Please enter your (4 digit) pin number: ") # display welcome message welcome_message()
d. The message should be followed by a display of menu options: balance enquiry, deposit, withdrawal, and exit (for example: “Enter 1 – To perform a balance enquiry.”) as the user is prompted to make their selection.
NB - Note in some cases you must make certain considerations (for example in the case of a withdrawal – Insufficient funds, the balance is only $$$ and in the case of deposits – Amount must be greater than $0 so to take care of negative deposits)
e. Importantly, this program must be continuous until broken by the option to exit and reflect all current balances with respect to transactions undertaken by user. For example: account balance once initialized as 5375.27, will display 5375.27 for balance enquiry given selection of 1. If followed by withdrawal of 500.00 given selection of 2, new account balance should display 4875.27 and so on… until broken by selection to exit
#import datetime that helps to print greetiing like Good morning,Good Evening and Good Night
import datetime
currentTime = datetime.datetime.now()
currentTime.hour
#Function to print Welcome Message
def welcome_message():
if currentTime.hour < 12:
print('Good morning, Welcome to Sussex Bank')
elif 12 <= currentTime.hour < 18:
print('Good afternoon, Welcome to Sussex Bank')
else:
print('Good Night, Welcome to Sussex Bank')
#Function for the working of ATM like deposit,withdraw and exit
def atm_login():
pin_number = input("Please enter your (4 digit) pin number: ") #To take the input for pin number
welcome_message();#Call Welcome Message
balance = 5375.27#initialize the initial balance with amount $5375.27
re=('Y')#To repeat the loop again and again until option is no or choice is 4 i.e. Exit
while re not in ('n','NO','no','N'):
print('Please Press 1 For Your Balance Enquiry')
print('Please Press 2 For Deposit')
print('Please Press 3 For Withdrawl')
print('Please Press 4 For Exit')
option = int(input('What Would you like to choose?'))
# For Balance Enquiry
if option == 1:
print('Your Balance is $',balance)
re = input('Would You you like to go back? ')
if re in ('n','NO','no','N'):
print('Thank You')
break
#For Depsoit the money
elif option == 2:
dep = float(input('How Much Would You Like Deposit? '))
if(dep>0):
balance = balance + dep
print ('Your Balance is now $',balance)
re = input('Would You you like to go back? ')
if re in ('n','NO','no','N'):
print('Thank You')
break
else:
print("Amount must be greater than $0")
elif option == 3:
withdrawl = float(input('How Much Would you like to withdraw?'))
if balance-withdrawl>=0:
balance = balance - withdrawl
print ('Your Balance is now $',balance)
re = input('Would You you like to go back? ')
if re in ('n','NO','no','N'):
print('Thank You')
break
else :
print("Insufficient Funds, The balance is only $ ",balance)
#Press 4 for Exit option
elif option == 4:
print('Please wait while your ATM card is Returned')
print('Thank you for you service')
break
return
#Call Atm Login Function
atm_login()