<filename>PyBank/mainpbank.py
#python-challenge p1 PYBANK
#Stablish the path towards the csv file
import os
import csv
bankdata_csv=os.path.join('R1', 'budget_data.csv')
#print(bankdata_csv) test succesfully 1 try
#stablish variables for the analysis
Num_month = 0
Profit = 0
PreviousProf = 0
Profit_change = 0
Sum_Profit_change = 0
Profit_change_list = []
Month_List = []
Great_Increase = ["", 0]
Great_Decrease = ["", 99999999999]
with open(bankdata_csv,newline="") as csvfile:
    csvreader = csv.reader(csvfile, delimiter=",")
    header = next(csvreader)
    PreviousProf = int(next(csvreader)[1])
    #print(csvreader) #test succesfully 3 try
    #print(type(PreviousProf)) #test done to verify variables for the average change answer
    #print(PreviousProf) #test done to verify variables for theaverage change answer
    #Stablish loop in the csv and start calculation with variables prestablish
    for row in csvreader:
        #print(row) #test done to verify variables in the csv
        Num_month += 1
        Profit = Profit+int(row[1])
        Profit_change = int(row[1]) - PreviousProf
        Sum_Profit_change = Sum_Profit_change + Profit_change
        #print(Sum_Profit_change) test to finde numbers for the average_change answer
        PreviousProf = int(row[1])
        #Month_List = Month_List + int(row[0])
        Month_List.append([row[0]])
        #Profit_change_list = Profit_change_list + [row[1]]
        #Stablish Conditionals in order to see evaluate the profit performance
        if (Profit_change > Great_Increase[1]): #test succesfull 5 try
            Great_Increase[1] = Profit_change
            Great_Increase[0] = row[0]
        elif (Profit_change < Great_Decrease[1]): #test succesfull 4 time
            Great_Decrease[1] = Profit_change
            Great_Decrease[0] = row[0]
    #Profit_change_list.append(Profit_change)
    #print("This is my sum of changes:",Sum_Profit_change ) #sum overall profit
    Profit_avg= (Sum_Profit_change)/(Num_month)  #try 55
    #Profit_change_list= Profit_change_list +[row[1]]
    print(f"The Total months used for the Net Profit Analysis were: {Num_month}")
    print(f"The net Profit produced by the bank was: ${Profit}")
    print(f"The Average Profit change generated by the bank was ${Profit_avg}")
    print(f"The Bank profits generated his greatest peak on {Great_Increase[0]},making ${Great_Increase[1]} ")
    print(f"The Bank profits generated lowest performance on {Great_Decrease[0]},making ${Great_Decrease[1]}") 
    #Analysis and resutls
    print(f"--------------------------Financial Analysis----------------------------------") #succsfull try 25
    print(f"------------------------------------------------------------------------------") #sucesfull try 25
    print(f"Total Months: --------------------------------------------------------------{Num_month}")
    print(f"Net Profit:--------------------------------------------------------- ${Profit}") #succesfull try 25
    print(f"Average Monthly Change:---------------------------------- ${Profit_avg}")
    print(f"Greatest Increase in Profits:--------------------------------{Great_Increase[0]} ${Great_Increase[1]}") #succesfull try42
    print(f"Greatest Loss In Profits:-----------------------------------{Great_Decrease[0]} ${Great_Decrease[1]}") #succesfull try 42
    #results were given in 25 trys 

    # Export results into a text file
    bankdata_output = os.path.join('Pybankdataresults.txt')  
    with open(bankdata_output, 'w') as txtfile:
        txtfile.write('\n----------------------------Financial Analysis--------------------------------')
        txtfile.write('\n------------------------------------------------------------------------------')
        txtfile.write(f'\nTotal Months:-------------------------------------------------------------- {Num_month}') #succesful try  32
        txtfile.write(f'\nNet Profit:----------------------------------------------------------${Profit}') #succesful try  32
        txtfile.write(f'\nAverage Monthly Change:-----------------------------------${Profit_avg}')
        txtfile.write(f'\nGreatest Increase In Profits:------------------------------- {Great_Increase[0]} ${Great_Increase[1]}') #succesful try  32
        txtfile.write(f'\nGreatest Loss In Profits:---------------------------------- {Great_Decrease[0]} ${Great_Decrease[1]}') #succesful try
        txtfile.write('\n------------------------------------------------------------------------------')
        txtfile.write('\n------------------------------------------------------------------------------')
        txtfile.write('\nStudent--------------------------------------<NAME>---')
<filename>PyBank/mainpbank.py
#python-challenge p1 PYBANK
#Stablish the path towards the csv file
import os
import csv
bankdata_csv=os.path.join('R1', 'budget_data.csv')
#print(bankdata_csv) test succesfully 1 try
#stablish variables for the analysis
Num_month = 0
Profit = 0
PreviousProf = 0
Profit_change = 0
Sum_Profit_change = 0
Profit_change_list = []
Month_List = []
Great_Increase = ["", 0]
Great_Decrease = ["", 99999999999]
with open(bankdata_csv,newline="") as csvfile:
    csvreader = csv.reader(csvfile, delimiter=",")
    header = next(csvreader)
    PreviousProf = int(next(csvreader)[1])
    #print(csvreader) #test succesfully 3 try
    #print(type(PreviousProf)) #test done to verify variables for the average change answer
    #print(PreviousProf) #test done to verify variables for theaverage change answer
    #Stablish loop in the csv and start calculation with variables prestablish
    for row in csvreader:
        #print(row) #test done to verify variables in the csv
        Num_month += 1
        Profit = Profit+int(row[1])
        Profit_change = int(row[1]) - PreviousProf
        Sum_Profit_change = Sum_Profit_change + Profit_change
        #print(Sum_Profit_change) test to finde numbers for the average_change answer
        PreviousProf = int(row[1])
        #Month_List = Month_List + int(row[0])
        Month_List.append([row[0]])
        #Profit_change_list = Profit_change_list + [row[1]]
        #Stablish Conditionals in order to see evaluate the profit performance
        if (Profit_change > Great_Increase[1]): #test succesfull 5 try
            Great_Increase[1] = Profit_change
            Great_Increase[0] = row[0]
        elif (Profit_change < Great_Decrease[1]): #test succesfull 4 time
            Great_Decrease[1] = Profit_change
            Great_Decrease[0] = row[0]
    #Profit_change_list.append(Profit_change)
    #print("This is my sum of changes:",Sum_Profit_change ) #sum overall profit
    Profit_avg= (Sum_Profit_change)/(Num_month)  #try 55
    #Profit_change_list= Profit_change_list +[row[1]]
    print(f"The Total months used for the Net Profit Analysis were: {Num_month}")
    print(f"The net Profit produced by the bank was: ${Profit}")
    print(f"The Average Profit change generated by the bank was ${Profit_avg}")
    print(f"The Bank profits generated his greatest peak on {Great_Increase[0]},making ${Great_Increase[1]} ")
    print(f"The Bank profits generated lowest performance on {Great_Decrease[0]},making ${Great_Decrease[1]}") 
    #Analysis and resutls
    print(f"--------------------------Financial Analysis----------------------------------") #succsfull try 25
    print(f"------------------------------------------------------------------------------") #sucesfull try 25
    print(f"Total Months: --------------------------------------------------------------{Num_month}")
    print(f"Net Profit:--------------------------------------------------------- ${Profit}") #succesfull try 25
    print(f"Average Monthly Change:---------------------------------- ${Profit_avg}")
    print(f"Greatest Increase in Profits:--------------------------------{Great_Increase[0]} ${Great_Increase[1]}") #succesfull try42
    print(f"Greatest Loss In Profits:-----------------------------------{Great_Decrease[0]} ${Great_Decrease[1]}") #succesfull try 42
    #results were given in 25 trys 

    # Export results into a text file
    bankdata_output = os.path.join('Pybankdataresults.txt')  
    with open(bankdata_output, 'w') as txtfile:
        txtfile.write('\n----------------------------Financial Analysis--------------------------------')
        txtfile.write('\n------------------------------------------------------------------------------')
        txtfile.write(f'\nTotal Months:-------------------------------------------------------------- {Num_month}') #succesful try  32
        txtfile.write(f'\nNet Profit:----------------------------------------------------------${Profit}') #succesful try  32
        txtfile.write(f'\nAverage Monthly Change:-----------------------------------${Profit_avg}')
        txtfile.write(f'\nGreatest Increase In Profits:------------------------------- {Great_Increase[0]} ${Great_Increase[1]}') #succesful try  32
        txtfile.write(f'\nGreatest Loss In Profits:---------------------------------- {Great_Decrease[0]} ${Great_Decrease[1]}') #succesful try
        txtfile.write('\n------------------------------------------------------------------------------')
        txtfile.write('\n------------------------------------------------------------------------------')
        txtfile.write('\nStudent--------------------------------------<NAME>---')
#python-challenge p1 PYBANK #Stablish the path towards the csv file #print(bankdata_csv) test succesfully 1 try #stablish variables for the analysis #print(csvreader) #test succesfully 3 try #print(type(PreviousProf)) #test done to verify variables for the average change answer #print(PreviousProf) #test done to verify variables for theaverage change answer #Stablish loop in the csv and start calculation with variables prestablish #print(row) #test done to verify variables in the csv #print(Sum_Profit_change) test to finde numbers for the average_change answer #Month_List = Month_List + int(row[0]) #Profit_change_list = Profit_change_list + [row[1]] #Stablish Conditionals in order to see evaluate the profit performance #test succesfull 5 try #test succesfull 4 time #Profit_change_list.append(Profit_change) #print("This is my sum of changes:",Sum_Profit_change ) #sum overall profit #try 55 #Profit_change_list= Profit_change_list +[row[1]] #Analysis and resutls #succsfull try 25 #sucesfull try 25 #succesfull try 25 #succesfull try42 #succesfull try 42 #results were given in 25 trys # Export results into a text file #succesful try  32 #succesful try  32 #succesful try  32 #succesful try