0% found this document useful (0 votes)
3 views

lab terminal

The document outlines a simple banking system implemented in Python, allowing users to create accounts, deposit and withdraw money, and check their balance. It includes functions for account management and a main loop for user interaction. The example output demonstrates the functionality of the system with various user inputs and responses.

Uploaded by

farhanjaffar12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

lab terminal

The document outlines a simple banking system implemented in Python, allowing users to create accounts, deposit and withdraw money, and check their balance. It includes functions for account management and a main loop for user interaction. The example output demonstrates the functionality of the system with various user inputs and responses.

Uploaded by

farhanjaffar12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME: FARHAN JAFFAR KHAN

REG NO: SP24-BAI-016

PROGRAM:

accounts = {}

def create_account(name, initial_balance):

account_number = len(accounts) + 1

accounts[account_number] = {'name': name, 'balance': initial_balance}

return account_number

def deposit(account_number, amount):

if account_number in accounts:

accounts[account_number]['balance'] += amount

return accounts[account_number]['balance']

else:

return "Error: Account not found."

def withdraw(account_number, amount):

if account_number in accounts:

if amount <= accounts[account_number]['balance']:

accounts[account_number]['balance'] -= amount

return accounts[account_number]['balance']

else:

return "Error: Insufficient funds."

else:
return "Error: Account not found."

def check_balance(account_number):

if account_number in accounts:

return accounts[account_number]['balance']

else:

return "Error: Account not found."

def main():

while True:

print("\nOptions:")

print("1. Create an account")

print("2. Deposit money")

print("3. Withdraw money")

print("4. Check balance")

print("5. Exit")

choice = int(input("Enter your choice: "))

if choice == 1:

name = input("Enter your name: ")

initial_balance = float(input("Enter initial balance: "))

account_number = create_account(name, initial_balance)

print(f"Account created with account number {account_number}.")

elif choice == 2:

account_number = int(input("Enter account number: "))


amount = float(input("Enter amount to deposit: "))

balance = deposit(account_number, amount)

if type(balance) == float:

print(f"Amount deposited. Current balance: {balance:.2f}")

else:

print(balance)

elif choice == 3:

account_number = int(input("Enter account number: "))

amount = float(input("Enter amount to withdraw: "))

balance = withdraw(account_number, amount)

if type(balance) == float:

print(f"Amount withdrawn. Current balance: {balance:.2f}")

else:

print(balance)

elif choice == 4:

account_number = int(input("Enter account number: "))

balance = check_balance(account_number)

if type(balance) == float:

print(f"Current balance: {balance:.2f}")

else:

print(balance)

elif choice == 5:

print("Exiting...")

break
else:

print("Invalid choice. Please try again.")

if __name__ == "__main__":

main()

OUTPUT:
Options:

1. Create an account

2. Deposit money

3. Withdraw money

4. Check balance

5. Exit

Enter your choice: 1

Enter your name: farhan

Enter initial balance: 20000

Account created with account number 1.

Options:

1. Create an account

2. Deposit money

3. Withdraw money

4. Check balance
5. Exit

Enter your choice: 2

Enter account number: 1

Enter amount to deposit: 2345

Amount deposited. Current balance: 22345.00

Options:

1. Create an account

2. Deposit money

3. Withdraw money

4. Check balance

5. Exit

Enter your choice: 3

Enter account number: 1

Enter amount to withdraw: 56098

Error: Insufficient funds.

Options:

1. Create an account

2. Deposit money

3. Withdraw money

4. Check balance

5. Exit

Enter your choice: 3

Enter account number: 1

Enter amount to withdraw: 768

Amount withdrawn. Current balance: 21577.00


Options:

1. Create an account

2. Deposit money

3. Withdraw money

4. Check balance

5. Exit

Enter your choice: 4

Enter account number: 1

Current balance: 21577.00

Options:

1. Create an account

2. Deposit money

3. Withdraw money

4. Check balance

5. Exit

Enter your choice: 5

Exiting...

You might also like