diff --git a/cs171/lect02/debug.py b/cs171/lect02/debug.py new file mode 100644 index 0000000000000000000000000000000000000000..0852eb63bd00462469e902ced6ad93576d435c07 --- /dev/null +++ b/cs171/lect02/debug.py @@ -0,0 +1,9 @@ +def addThese(a, b): + return a + b + +# print(addThese(22, 7)) + +import hello +import math + +print(hello.totalCollegeTuition(10000, 2)) \ No newline at end of file diff --git a/cs171/lect02/hello.py b/cs171/lect02/hello.py index 061448a8d1383c3b10b99d3b4667be38bd953c3a..da67a45b59c24fde45df51f92b6948520ff93dff 100644 --- a/cs171/lect02/hello.py +++ b/cs171/lect02/hello.py @@ -1 +1,35 @@ -print("Hello CS 171") +def totalCollegeTuition(costPerTerm, numTerms): + return costPerTerm * numTerms + +def loanPayment(principal, rate, numMonths): + rate = rate / 12 + onePlus = ((1 + rate) ** numMonths) + numerator = rate * onePlus + denominator = onePlus - 1 + payment = principal * (numerator / denominator) + return payment + +def yearsToRepay(amountOwed, hourlyWage): + hours = amountOwed / hourlyWage + weeks = hours / 40 + years = weeks / 52 + return years + +if __name__ == "__main__": + + uniName = input("Name of university:\n") + costPerTerm = float(input("How much does one term cost?\n")) + numTerms = int(input("How many terms are required to graduate?\n")) + apr = float(input("What is the annual percentage rate? (ex: 0.055)\n")) + numYears = int(input("How many year will you take to pay it back?\n")) + months = numYears * 12 + + totalTuition = totalCollegeTuition(costPerTerm, numTerms) + payment = loanPayment(totalTuition, apr, months) + + print("Your total tuition will be", totalTuition) + print("Your monthly payment will be", payment) + totalLoanCost = payment * months + print("Your sum of payments is", totalLoanCost) + years = yearsToRepay(totalLoanCost, 7.25) + print("You would need to work", years, "years at minimum wage to repay your loan for attending", uniName)