Bank Managing 1.0
Bank Managing 1.0
Bank Managing 1.0
Import random
Import os
# Constants
DATABASE_FILE = “bank_accounts.csv”
ADMIN_PASSWORD = “admin123”
Def initialize_database():
If not os.path.exists(DATABASE_FILE):
Writer = csv.writer(file)
Def generate_account_number():
Def create_account():
While True:
Try:
If initial_deposit < 0:
Break
Except ValueError as e:
Account_number = generate_account_number()
Writer = csv.writer(file)
Def deposit():
While True:
Try:
If amount <= 0:
Break
Except ValueError as e:
Accounts = load_accounts()
If account[‘AccountNumber’] == account_number:
Save_accounts(accounts)
Print(“Deposit successful!”)
Return
Def withdraw():
While True:
Try:
Break
Except ValueError as e:
Accounts = load_accounts()
Save_accounts(accounts)
Print(“Withdrawal successful!”)
Return
Else:
Print(“Insufficient balance.”)
Return
Def transfer():
While True:
Try:
If amount <= 0:
Break
Except ValueError as e:
Accounts = load_accounts()
From_account_data = None
To_account_data = None
From_account_data = account
If account[‘AccountNumber’] == to_account:
To_account_data = account
From_account_data[‘Balance’] =
str(float(from_account_data[‘Balance’]) – amount)
To_account_data[‘Balance’] = str(float(to_account_data[‘Balance’]) +
amount)
Save_accounts(accounts)
Print(“Transfer successful!”)
Else:
Print(“Insufficient balance.”)
Else:
Def update_account():
Accounts = load_accounts()
Account_found = False
Account_found = True
Print(“1. Username”)
Print(“2. Password”)
If choice == ‘1’:
Account[‘Username’] = new_username
Print(“Username updated successfully!”)
Account[‘Password’] = new_password
Else:
Save_accounts(accounts)
Break
If not account_found:
Def apply_for_loan():
Accounts = load_accounts()
Print(“\nLoan Eligibility:”)
Return
While True:
Try:
If loan_amount <= 0:
Else:
Save_accounts(accounts)
Return
Except ValueError as e:
Print(f”Invalid input: {e}”)
Def repay_loan():
Accounts = load_accounts()
If loan_amount <= 0:
Return
While True:
Try:
If repay_amount <= 0:
Else:
Loan_amount -= repay_amount
Account[‘Loan’] = str(loan_amount)
Account[‘Balance’] = str(float(account[‘Balance’]) –
repay_amount)
Save_accounts(accounts)
Return
Except ValueError as e:
Def show_my_account():
Accounts = load_accounts()
Print(f”Username: {account[‘Username’]}”)
Print(f”Balance: {account[‘Balance’]}”)
Return
Print(“Invalid account number or password.”)
Def show_all_accounts():
If admin_password != ADMIN_PASSWORD:
Return
Accounts = load_accounts()
Print(f”{‘Username’:<20}{‘AccountNumber’:<15}{‘Balance’:<10}
{‘IsAdmin’:<8}”)
Print(“-“ * 60)
Print(f”{account[‘Username’]:<20}{account[‘AccountNumber’]:<15}
{account[‘Balance’]:<10}{account[‘IsAdmin’]:<8}”)
Def delete_account():
If admin_password != ADMIN_PASSWORD:
Return
Account_number = input(“Enter the account number to delete: “).strip()
Accounts = load_accounts()
Save_accounts(accounts)
Def load_accounts():
Reader = csv.DictReader(file)
Return list(reader)
Def save_accounts(accounts):
Writer.writeheader()
Writer.writerows(accounts)
Initialize_database()
While True:
Print(“2. Deposit”)
Print(“3. Withdraw”)
Print(“4. Transfer”)
Print(“11. Exit”)
If choice == ‘1’:
Create_account()
Deposit()
Withdraw()
Transfer()
Apply_for_loan()
Repay_loan()
Show_my_account()
Show_all_accounts()
Delete_account()
Break
Else:
If __name__ == “__main__”:
Main_menu()