python - How do I keep a running total for every time the tuition increases and add those values together? -


college cost estimator

def calculatetuitionincrease(cost, increase, years):       #this function calculates projected tuition increase each year.       counter = 0       while counter <= years:           increasedcost = (cost)+(cost*increase)           return increasedcost  def calculatetotalcost(terms,tuition,credithours,books,roomandboard,scholarships):       #this function calculate total cost of expenses.       totalbookcost = (books*terms)       totaltuitioncost = (tuition*credithours)*(terms)       totalroomandboard =(roomandboard*terms)     totalcost = (totalbookcost+totaltuitioncost+totalroomandboard)-(scholarships)       return totalcost   def main():      #variable declaration/initialization     years = 0     terms = 0     numberofschools = 0      tuitioncost1 = 0     tuitioncost2 = 0     tuitioncost3 = 0     tuitioncost = 0      bookcost = 0     roomandboard = 0     scholarships = 0      tuitionincrease = 0     increasedcost = 0      credithours = 0     overallcost = 0      #user inputs     years = int(input("will going school 2, 4 or 6 years?"))      #if-statements if user going multiple schools.     if years == 4 or years == 6:         numberofschools = int(input("how many schools plan on attending during time?"))      if numberofschools == 2:         tuitioncost1 = int(input("how paying per credit hour @ first school you'll attending?"))         tuitioncost2 = int(input("how paying per credit hour @ second school you'll attending?"))         tuitioncost = (tuitioncost1+tuitioncost2)/(2) #finds average tuition between schools & assigns variable      elif numberofschools == 3:         tuitioncost1 = int(input("how paying per credit hour @ first school you'll attending?"))         tuitioncost2 = int(input("how paying per credit hour @ second school you'll attending?"))         tuitioncost3 = int(input("how paying per credit hour @ third school you'll attending?"))         tuitioncost = (tuitioncost1+tuitioncost2+tuitioncost3)/(3) #finds average tuition cost between schools & assigns variable      else:         tuitioncost = int(input("please enter how paying per credit hour."))      terms = (years*2)      tuitionincrease = float(input("please enter projected tuition increase per year in percentage form (ex. if increase 7% enter .07)."))     credithours = int(input("on average, how many credit hours receiving per term?"))     roomandboard = int(input("please enter price of room , board per term."))     bookcost = int(input("please enter average book cost per term."))     scholarships = int(input("please enter total amount recieving grants , scholarships."))      #calls function calculates tuition increase     increasedcost = calculatetuitionincrease(tuitioncost,tuitionincrease,years)      #calls function calculates tuition increase     overallcost = calculatetotalcost(terms,tuitioncost,credithours,bookcost,roomandboard,scholarships)      print ("your total estimated college cost is", overallcost)  main() 

generally running total or running average calculate through several iterations of code. however, don't see loops here.

perhaps mean you'd sum of costs of each school tuition.

in case, there when calculated average. create variable can hold total cost values functions.

as results function:

tuitiontotal = (tuitioncost1+tuitioncost2+tuitioncost3) * tuitionincrease 

it seems may able clean logic of code little bit well. i'd suggest asking of questions front, doing calculations afterward.

something might help:

tuitioncost = 0 cost_text = "how paying per credit hour @ school number "  ...  in range(numberofschools):     tuitioncost += int(input(cost_text+str(i+1)+"?"))  ...  tuitionaverage = tuitioncost / (i+1) tuitiontotal = tuitioncost * tuitionincrease 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -