Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: Banking ICSE Interest Calculator

Monday, January 30, 2023

Banking ICSE Interest Calculator

Calculation of interest on a savings bank account
Mini Python project for middle and high school students

Example




Run the code on google colaboratory
Python Code:
class Solution(object):

    def Banking(self, numberOfMonths):
        transactions = dict()
        for i in range(numberOfMonths):
            month = str(input("Enter the month:"))
            transactions_for_month = int(
                input("Enter the number of transactions for this month:"))
            tempList = []
            for j in range(transactions_for_month):
                tempList.append(int(input("Enter the date of the month:")))
                # put a negative sign before the number if the amount is withdrawn
                tempList.append(
                    float(input("Enter the amount deposited or withdrawn:")))
            transactions[month] = tempList
        #print(transactions)
        self.MinimumBalance(transactions)

    def MinimumBalance(self, transactions):
        key = list(transactions.keys())
        balance = []
        balanceFinal = 0
        date = []
        monthWiseMBList = []
        for i in range(len(transactions)):
            for j in range(len(transactions[key[i]])):
                if j % 2 == 0:
                    date.append(transactions[key[i]][j])
                else:
                    balanceFinal += (transactions[key[i]][j])
                    balance.append(balanceFinal)
            balanceFinal = balance[-1]
            #print(balance)
            #print(date)
            if i != 0:
                move_date += int((len(transactions[key[i - 1]]) / 2))
            else:
                move_date = 0
            #print(move_date)
            minimumBalanceMonthly = float('inf')
            flagTransactionLessThanTenth = False
           
            for k in range(len(date) - move_date):
                if date[k+move_date] <= 10:
                    minimumBalanceMonthly = balance[k + move_date]
                    flagTransactionLessThanTenth = True
                else:

                    if minimumBalanceMonthly > balance[k + move_date]:
                        minimumBalanceMonthly = balance[k + move_date]
            if len(transactions[key[i]]) == 0:
                monthWiseMBList.append(monthWiseMBList[i - 1])
            else:
                monthWiseMBList.append(minimumBalanceMonthly)
            if flagTransactionLessThanTenth == False:
                if i == 0:
                    print(monthWiseMBList[i], i, minimumBalanceMonthly)
                    monthWiseMBList[i] = 0
                if i!=0:
                    if monthWiseMBList[i] > monthWiseMBList[i - 1] and len(transactions[key[i]]) != 0:
                        monthWiseMBList[i] = monthWiseMBList[i - 1]
                    else:
                        monthWiseMBList[i] = balance[-1]
            if i == len(key) - 1:
                print("Press Y/y is the account was closed in the month of ", key[-1])
                choice = str(input())
                if choice == "Y" or choice == "y":
                    monthWiseMBList[-1] = 0
            print("Minimum Monthly Balance for the month of ", key[i], "= ",
                  monthWiseMBList[i])
        #calculation of interest
        qualifyingAmount = 0
        for j in (monthWiseMBList):
            qualifyingAmount += j
        print("Total of balances ", qualifyingAmount)
        rate_of_interest = float(input("Enter the rate of interest:"))
        interest = (qualifyingAmount * rate_of_interest * (1 / 12)) / 100.0
        print("Total interest earned = ", round(interest, 2))


obj = Solution()
numberOfmonths = int(input("Enter the number of months:"))
obj.Banking(numberOfmonths)






No comments:

Post a Comment