Python: Simple Banking Application
Project Solution: • Input file: The program starts with reading in all user information from a given input file. The input file contains information of a user in following order: username, first name, last name, password, account number and account balance. Information is separated with ‘|’. o username is a unique information, so no two users will have same username. Sample input file: Username eaglebank has password 123456, account number of BB12 and balance of $1000.
Program flows as below:
1) data is read in from the given input file,
2) it will be saved to a dictionary referred as users where each key is username and the value will be a list containing rest of the information: first name, last name, password, account number and account balance. One example of key-value pair is: 'eaglebank': ['Eagle', 'Bank', '123456', 'BB12', 1000.0]. 3) user will be presented with a menu and all the operations related to menu options will be performed on this users dictionary.
Main Menu: The program starts with a welcome message and displays main menu. Main menu contains following different options for a user:
Main Menu
1. New User
2. Sign In
3. Exit Application
(Option 1) New User: User has the option of creating a new account. Creating a new account implies adding a new key-value pair in users dictionary. Once account creation is successful, the program will display some informational message and will take user to the Main Menu for relogin. If user chooses a username that already exists, program will ask for another username until user inputs a different username. Hint: A while loop will help you to accomplish this repetition if user chooses an existing username. This scenario is very similar to any login system like mason username. Each user has a unique username. A sample interface can be as follows:
Outcome- 1 (no error)
New user
Enter first name: Jane
Enter last name: Doe
Enter your username: jdoe
Enter your password (between 6-12 characters): 1234567
Your random account number is JKBB
Enter initial balance to deposit: 89
Account jdoe added.
Please login again to start banking.
Outcome - 2 (with error – username already taken)
New user Enter first name: James
Enter last name: Madison
Enter your username: eaglebank
Username already taken. Please choose another username.
Enter your username: hawk
Username already taken. Please choose another username
Enter your username: jcon
Enter your password (between 6-12 characters): password
Your random account number is INRD
Enter initial balance to deposit: 1000
Account jcon added.
Please login again to start banking
(Option 2) Sign In: Existing users need to sign in to account using username and password. Once username and password matches, program will take user to existing user menu (see sub-options below for details). Each user has maximum three chances to login, once all the chances are used, program will display a message and take back to main menu.
Output - 1 (no error)
Enter username: eaglebank
Enter password: 123456
Login successful. Welcome eaglebank
Existing User Menu
1. Deposit
2. Withdraw
3. Fast Cash
4. Transfer
5. Account Summary
6. Logout Enter option (1-6):
Output- 2 (users try to login three times)
Enter option (1-3): 2
Enter username: eaglebank
Enter password: 45678910
Username and password do not match.
Enter username: eaglebank
Enter password: password
Username and password do not match.
Enter username: eaglebank
Enter password: 1234567!!
Username and password do not match. You tried to login three times. Taking to main menu.
CODE -
import string
import random
alphanumeric = string.ascii_uppercase + string.digits
acc_dict={}
account = open("bank.txt")
acc_list = [x.strip("\n").split("|") for x in account.readlines()]
for i in range(len(acc_list)):
acc_list[i][-1]=float(acc_list[i][-1])
acc_dict[acc_list[i][0]] = acc_list[i][1:]
print("\n*****WELCOME TO VISION BANKING APPLICATION*****\n")
while 1:
print("Main Menu \n1. New User \n2. Sign In \n3. Exit Application \n")
n=int(input("Enter your choice: "))
if n==1:
fname = input("Enter first name: ")
lname = input("Enter last name: ")
username = input("Enter your username: ")
while username in acc_dict:
print("Username already taken. Please choose another username.")
username = input("Enter your username: ")
password = input("Enter your password (between 6-12 characters): ")
while len(password)<6 or len(password)>12:
print("Password length should be between 6-12 characters.")
password = input("Enter your password (between 6-12 characters): ")
acc_no = ''.join((random.choice(alphanumeric) for i in range(4)))
print("Your random account number is",acc_no)
bal = float(input("Enter initial balance to deposit: "))
new_acc=[fname,lname,password,acc_no,bal]
acc_dict[username] = new_acc
print("Account",username,"added.")
print("Please login again to start banking.")
continue
elif n==2:
count = 0
flag = 0
username = input("Enter username: ")
password = input("Enter password: ")
while username not in acc_dict or acc_dict[username][2] != password:
print("Username and password do not match.")
count +=1
if count==3:
print("You tried to login three times. Taking to main menu.")
flag = 1
break
username = input("Enter username: ")
password = input("Enter password: ")
if flag ==1:
continue
else:
print("Login successful. Welcome",username)
print("Existing User Menu")
while 1:
print("1. Deposit \n2. Withdraw \n3. Fast Cash \n4. Transfer \n5. Account Summary \n6. Logout")
choice = int(input("Enter option (1-6)"))
if choice==1:
amt = float(input("Enter amount to deposit: "))
acc_dict[username][4] +=amt
print("Deposit Successful")
continue
elif choice==2:
flag=0
amt = float(input("Enter amount to withdraw: "))
if acc_dict[username][4]<amt:
print("Insufficient Funds in your account!")
flag = 1
break
if flag==1:
continue
acc_dict[username][4] -=amt
print("Withdrawal Successful")
continue
elif choice==3:
flag=0
print("1. 500 \n2. 1000 \n3. 5000")
x = int(input("Choose amount to withdraw: "))
if x==1:
if acc_dict[username][4]<500:
print("Insufficient Funds in your account!")
flag = 1
break
if flag==1:
continue
acc_dict[username][4] -=500
print("Withdrawal Successful")
continue
elif x==2:
if acc_dict[username][4]<1000:
print("Insufficient Funds in your account!")
flag = 1
break
if flag==1:
continue
acc_dict[username][4] -=1000
print("Withdrawal Successful")
continue
elif x==3:
if acc_dict[username][4]<5000:
print("Insufficient Funds in your account!")
flag = 1
break
if flag==1:
continue
acc_dict[username][4] -=5000
print("Withdrawal Successful")
continue
else:
print("Invalid input")
continue
elif choice==4:
user = input("Enter the username of user you want to transfer money: ")
if user not in acc_dict:
print("User does not exist")
continue
amt=float(input("Enter amount you want to transfer: "))
if acc_dict[username][4]<amt:
print("Insufficient Funds in your account!")
flag = 1
break
if flag==1:
continue
acc_dict[username][4] -=amt
acc_dict[user][4]+-amt
print("Transfer Successful")
continue
elif choice==5:
print("***Account Summary***")
print("First Name: ",acc_dict[username][0])
print("Last Name: ",acc_dict[username][1])
print("Username: ",username)
print("Account Number: ",acc_dict[username][3])
print("Account Balance: ",acc_dict[username][4])
elif choice==6:
break
else:
print("Invalid Choice!")
elif n==3:
exit(0)
else:
print("Invalid Choice!")
SCREENSHOTS -
CODE -
Get Answers For Free
Most questions answered within 1 hours.