Banking/bankAnalysis.py
def bank_analysis(bankCsvFile=None):
    """This function performs bank analysis on the data contained in a passed CSV file."""

    # Check that a file was passed
    if bankCsvFile == None:
        return []

    # Initialize variables used for bank analysis.
    greatestIncMonth = greatestDecMonth    = 'Undef'
    totalMonths = totalPandL = greatestInc = \
                  cumChanges = greatestDec = 0

    # Create an instance of ReadCsv for reading the bank CSV file
    bankData = ReadCsv(bankCsvFile)
    
    # Ignore the header row
    if len(bankData.next_row()) == 0:
        print(f"\nHeader row not found in CSV file {bankCsvFile}\n")
        return []
    
    # Read the first row of data.
    row = bankData.next_row()
    if len(row) == 0:
        print(f"\nNo data found in CSV file {bankCsvFile}")
        print("    after header row\n")
        return []
    elif len(row) != 2:
        print(f"\nUnexpected data found in CSV file {bankCsvFile}")
        print(f"    at line  {bankData.row_num()}\n")
        return []
    
    # Initialize variables that store the previous month and its profit/loss
    prevMonth = row[0]
    prevPandL = int(row[1])
    
    # Update totalMonths and totalPandL values to reflect row just read
    totalMonths += 1
    totalPandL += int(row[1])
    
    # Loop through each remaining row of data in the CSV file
    row = bankData.next_row()
    while len(row) == 2:
    
        # Update totalMonths and totalPandL values to reflect row just read
        totalMonths += 1
        totalPandL += int(row[1])
    
        # Calculate profit/loss change from previous month. Add this change to
        # the cumulative changes total.
        plChange = int(row[1]) - prevPandL
        cumChanges += plChange
    
        # Determine if 'current' Profit/Loss change is greater/less than stored
        # values
        if greatestInc < plChange:
            greatestInc = plChange
            greatestIncMonth = row[0]
        elif greatestDec > plChange: 
            greatestDec = plChange
            greatestDecMonth = row[0]
    
        # Update previous profit/loss value to current value
        prevPandL = int(row[1])
    
        # Read the next row
        row = bankData.next_row()
    
    else:
        if len(row) != 0:
            print(f"\nUnexpected data found in CSV file {bankCsvFile}")
            print(f"    at line  {bankData.row_num()}\n")
            return []
    
    # Set average of the changes in profit/losses
    if totalMonths == 1:
        averageChange = 0
    else:
        averageChange = cumChanges / (totalMonths - 1)
 
    # Create the List of the strings to return
    returnStrs = [
                    ("\n Financial Analysis\n -------------------------------\n"),
                    (f" Total Months: {totalMonths}\n"),
                    (f" Total: ${totalPandL}\n"),
                    (f" Average Change: ${round(averageChange, 2)}\n"),
                    (f" Greatest Increase in Profits: {greatestIncMonth}  (${greatestInc})\n"),
                    (f" Greatest Decrease in Profits: {greatestDecMonth}  (${greatestDec})\n")
                 ]
    
    # Return the List
    return returnStrs
This function performs bank analysis on the data contained in a passed CSV file.
This function performs bank analysis on the data contained in a passed CSV file.
This function performs bank analysis on the data contained in a passed CSV file .
def bank_analysis(bankCsvFile=None):
    if bankCsvFile == None:
        return []
    greatestIncMonth = greatestDecMonth    = 'Undef'
    totalMonths = totalPandL = greatestInc = \
                  cumChanges = greatestDec = 0
    bankData = ReadCsv(bankCsvFile)
    if len(bankData.next_row()) == 0:
        print(f"\nHeader row not found in CSV file {bankCsvFile}\n")
        return []
    row = bankData.next_row()
    if len(row) == 0:
        print(f"\nNo data found in CSV file {bankCsvFile}")
        print("    after header row\n")
        return []
    elif len(row) != 2:
        print(f"\nUnexpected data found in CSV file {bankCsvFile}")
        print(f"    at line  {bankData.row_num()}\n")
        return []
    prevMonth = row[0]
    prevPandL = int(row[1])
    totalMonths += 1
    totalPandL += int(row[1])
    row = bankData.next_row()
    while len(row) == 2:
        totalMonths += 1
        totalPandL += int(row[1])
        plChange = int(row[1]) - prevPandL
        cumChanges += plChange
        if greatestInc < plChange:
            greatestInc = plChange
            greatestIncMonth = row[0]
        elif greatestDec > plChange: 
            greatestDec = plChange
            greatestDecMonth = row[0]
        prevPandL = int(row[1])
        row = bankData.next_row()
    else:
        if len(row) != 0:
            print(f"\nUnexpected data found in CSV file {bankCsvFile}")
            print(f"    at line  {bankData.row_num()}\n")
            return []
    if totalMonths == 1:
        averageChange = 0
    else:
        averageChange = cumChanges / (totalMonths - 1)
    returnStrs = [
                    ("\n Financial Analysis\n -------------------------------\n"),
                    (f" Total Months: {totalMonths}\n"),
                    (f" Total: ${totalPandL}\n"),
                    (f" Average Change: ${round(averageChange, 2)}\n"),
                    (f" Greatest Increase in Profits: {greatestIncMonth}  (${greatestInc})\n"),
                    (f" Greatest Decrease in Profits: {greatestDecMonth}  (${greatestDec})\n")
                 ]
    return returnStrs
def bank_analysis ( bankCsvFile = None ) : if bankCsvFile == None : return [ ] greatestIncMonth = greatestDecMonth = 'Undef' totalMonths = totalPandL = greatestInc = cumChanges = greatestDec = 0 bankData = ReadCsv ( bankCsvFile ) if len ( bankData . next_row ( ) ) == 0 : print ( f"\nHeader row not found in CSV file {bankCsvFile}\n" ) return [ ] row = bankData . next_row ( ) if len ( row ) == 0 : print ( f"\nNo data found in CSV file {bankCsvFile}" ) print ( "    after header row\n" ) return [ ] elif len ( row ) != 2 : print ( f"\nUnexpected data found in CSV file {bankCsvFile}" ) print ( f"    at line  {bankData.row_num()}\n" ) return [ ] prevMonth = row [ 0 ] prevPandL = int ( row [ 1 ] ) totalMonths += 1 totalPandL += int ( row [ 1 ] ) row = bankData . next_row ( ) while len ( row ) == 2 : totalMonths += 1 totalPandL += int ( row [ 1 ] ) plChange = int ( row [ 1 ] ) - prevPandL cumChanges += plChange if greatestInc < plChange : greatestInc = plChange greatestIncMonth = row [ 0 ] elif greatestDec > plChange : greatestDec = plChange greatestDecMonth = row [ 0 ] prevPandL = int ( row [ 1 ] ) row = bankData . next_row ( ) else : if len ( row ) != 0 : print ( f"\nUnexpected data found in CSV file {bankCsvFile}" ) print ( f"    at line  {bankData.row_num()}\n" ) return [ ] if totalMonths == 1 : averageChange = 0 else : averageChange = cumChanges / ( totalMonths - 1 ) returnStrs = [ ( "\n Financial Analysis\n -------------------------------\n" ) , ( f" Total Months: {totalMonths}\n" ) , ( f" Total: ${totalPandL}\n" ) , ( f" Average Change: ${round(averageChange, 2)}\n" ) , ( f" Greatest Increase in Profits: {greatestIncMonth}  (${greatestInc})\n" ) , ( f" Greatest Decrease in Profits: {greatestDecMonth}  (${greatestDec})\n" ) ] return returnStrs
This function performs bank analysis on the data contained in a passed CSV file.
This function performs bank analysis on the data contained in a passed CSV file .
"""This function performs bank analysis on the data contained in a passed CSV file.""" # Check that a file was passed # Initialize variables used for bank analysis. # Create an instance of ReadCsv for reading the bank CSV file # Ignore the header row # Read the first row of data. # Initialize variables that store the previous month and its profit/loss # Update totalMonths and totalPandL values to reflect row just read # Loop through each remaining row of data in the CSV file # Update totalMonths and totalPandL values to reflect row just read # Calculate profit/loss change from previous month. Add this change to # the cumulative changes total. # Determine if 'current' Profit/Loss change is greater/less than stored # values # Update previous profit/loss value to current value # Read the next row # Set average of the changes in profit/losses # Create the List of the strings to return # Return the List
bankCsvFile