Advertisement
emadjshah

atm.py

Jun 25th, 2022
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. from datetime import datetime
  2. date=datetime.today()
  3. date=date.strftime('%Y/%B/%d %H:%M:%S %p')
  4.  
  5. users={'1111':'user1','2222':'user2','3333':'user3','4444':'user4'}
  6. user_amt={'1111':1000,'2222':2000,'3333':3000,'4444':4000}
  7.  
  8. print('Welcome to Py Bank!')
  9. trial=0
  10. while trial<=3:
  11.     pin=input('\nEnter your atm pin:')
  12.     if pin.isdigit()==True and len(pin)==4 and pin in users.keys():
  13.         print('Hello!',users[pin],'\nLog in Successful!')
  14.         break
  15.     else:
  16.         print('Invalid Input.\nTry again.')
  17.         trial+=1
  18. else:
  19.     print('Four attempts failed.\nThis card has been blocked.')
  20.     exit()
  21.  
  22. def get_acct_statement():
  23.     print('\nDear',users[pin],'\nAccount balance as at',date,':','N',user_amt[pin])
  24.    
  25. def withdrawal():
  26.     attempt=0
  27.     while attempt<=3:
  28.         amt=int(input("\nEnter amount to withdraw:"))
  29.         if amt<200 or amt>user_amt[pin]:
  30.             print("Withdrawal failed!\nYou can't withdraw lower than N200 or higher than your available balance.\nYour current balance is:N",user_amt[pin])
  31.             attempt+=1
  32.         else:
  33.             print("Withdrawal Successful!\nPlease wait and collect you cash.")
  34.             break
  35.     else:
  36.         print('Four attempts failed.\nTry again later.')
  37.         exit()
  38.        
  39. def deposit():
  40.     attempt=0
  41.     while attempt<=3:
  42.         amt=int(input('\nEnter amount to deposit:'))
  43.         if amt<1000 or amt>100000:
  44.             print("Deposit failed!\nYou can't deposit less than N1000 or more than N100000.")
  45.             attempt+=1
  46.         else:
  47.             total=amt+user_amt[pin]
  48.             print('Deposit Successful.\nYour new balance as at:',date,':N',total)
  49.             break
  50.     else:
  51.         print('Four attempts failed.\nTry again later.')
  52.         exit()
  53.  
  54. def change_pin():
  55.     attempt=0
  56.     while attempt<=3:
  57.         pin2=input('\nEnter new pin:')
  58.         if pin2.isdigit()==True and len(pin2)==4 and pin2!=pin:
  59.             attempt2=0
  60.             while attempt2<=3:
  61.                 pin3=input('Confirm new pin:')
  62.                 if pin2==pin3:
  63.                     print("You've successfully changed your pin!\nYour new pin is:",pin3)
  64.                     break
  65.                 else:
  66.                     print('Invalid pin.\nTry again.')
  67.                     attempt2+=1
  68.             else:
  69.                     print('Four attempts failed.\nThis card has been blocked.')
  70.                     exit()
  71.         else:
  72.             print('Invalid pin.\nEnsure that new pin is of four digits and not same as old pin.\nTry again.')
  73.             attempt+=1
  74.     else:
  75.         print('Four attempts failed.\nTry again later.')
  76.         exit()
  77.  
  78. def operations():
  79.     print('\nSelect any of the options by inputting the appropriate number.')
  80.     print('1.Get Account Statement','\n2.Withdrawal','\n3.Deposit','\n4.Change Pin','\n5.Quit.')
  81.     reply=input('Enter number:')
  82.     if reply=='1':
  83.         get_acct_statement()
  84.     elif reply=='2':
  85.         withdrawal()
  86.     elif reply=='3':
  87.         deposit()
  88.     elif reply=='4':
  89.         change_pin()
  90.     elif reply=='5':
  91.         exit()
  92.     else:
  93.         print('Invalid Input.\nThank you, for using Py Bank!')
  94.         exit()
  95.  
  96. while True:
  97.     operations()
  98.     reply=input("\nWould you like to perfom another transaction?\nY or N:").lower()
  99.     if reply=='y':
  100.         continue
  101.     elif reply=='n':
  102.         print('Thank you, for using Py Bank!')
  103.         break
  104.     else:
  105.         print('I do not understand.')
  106.         exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement