Bank Management System Program in Python

Here, we are implementing a Python program that will be used to calculate Net amount of a bank account based on the transactions. By IncludeHelp Last updated : April 14, 2023

Bank Management System Program

Given a few transactions (deposit, withdrawal), and we have to compute the Net Amount of that bank account based on these transactions in Python.

Bank Management System Example

Input:
Enter transactions: D 10000
Want to continue (Y for yes): Y
Enter transaction: W 5000
Want to continue (Y for yes): Y
Enter transaction: D 2000
Want to continue (Y for yes): Y
Enter transaction: W 100
Want to continue (Y for yes): N

Output:
Net amount: 6900

Logic to Write Bank Management System Program

  • For this program, we will input transactions (till user's choice is "Y") with type ("D" for deposit and "W" for withdrawal) and the amount – for that we will computer it in an infinite loop while True:
  • Transactions will be like "D 2000" that means Deposit 2000, so there are two values needs to be extracted 1) "D" is the type of transaction and 2) 2000 is the amount to be deposited.
  • A transaction input will be string type- convert/split the values to the list which is delimited by the space. For this, we use string.split() method.
  • Now, the values will be in the list, the first value is the type – which is in string format and the second value is the amount – which is in also string format, we need to convert the amount in integer format. So we will convert its type (example code: amount = int(list[1])).
  • After that, based on the transaction type check the conditions and adding/subtracting the amount from the net amount.
  • After that, ask for the user for the next transaction and check the weather, if the user's choice is not "Y" or "y", break the loop and print the net amount.

Python Code for Bank Management System Program

# computes net bank amount based on the input
# "D" for deposit, "W" for withdrawal

# define a variable for main amount
net_amount = 0

while True:
    # input the transaction
    str = input("Enter transaction: ")

    # get the value type and amount to the list
    # seprated by space
    transaction = str.split(" ")

    # get the value of transaction type and amount
    # in the separated variables
    type = transaction[0]
    amount = int(transaction[1])

    if type == "D" or type == "d":
        net_amount += amount
    elif type == "W" or type == "w":
        net_amount -= amount
    else:
        pass

    # input choice
    str = input("want to continue (Y for yes) : ")
    if not (str[0] == "Y" or str[0] == "y"):
        # break the loop
        break

# print the net amount
print("Net amount: ", net_amount)

Output

Enter transaction: D 10000
want to continue (Y for yes) : Y
Enter transaction: W 5000
want to continue (Y for yes) : Y
Enter transaction: D 2000
want to continue (Y for yes) : Y
Enter transaction: W 100
want to continue (Y for yes) : N
Net amount:  6900

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.