Skip to main content
Code Review

Return to Question

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best practice? To revise my new version, Python tuition calculator 2.0 Python tuition calculator 2.0

I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best practice? To revise my new version, Python tuition calculator 2.0

I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best practice? To revise my new version, Python tuition calculator 2.0

added 110 characters in body
Source Link
Aaron
  • 357
  • 1
  • 4
  • 11

I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best practice? To revise my new version, Python tuition calculator 2.0

I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best practice?

I'm a student learning Python, I made this calculator that will tell you the tuition for the next 5 years at an increase of 3% per year. How can I improve on this and did I do anything that isn't best practice? To revise my new version, Python tuition calculator 2.0

edited back 2 version to original
Source Link
Aaron
  • 357
  • 1
  • 4
  • 11
RESIDENCY_COSTinState = {
  "I": 10000,
outState "O":= 24000,
profGrad "G":= 40000,

years = }
[]
cost_of_tuitiontuitionIncrease = None[]
while True:
 residency
i = raw_input('Please input your type of residency, I for in-state, O for out-of-state, and G for graduate: ')

if i == try'I':
 cost_of_tuitioncostOfTuition = RESIDENCY_COST[residency]
 breakinState
elif i except== ValueError'O':
 print ('Please enter I, G orcostOfTuition O= ONLY.')outState
elif i == 'G':
years = []
tuition_increase = []
academic_yearcostOfTuition = []profGrad
academic_year_inc
x = []
0
forwhile _x in!= range(5):
 intMath = cost_of_tuitioncostOfTuition * 0.03
 tuition_increasetuitionIncrease.append(intMath)
 fnlMath = intMath + cost_of_tuitioncostOfTuition
 years.append(fnlMath)
 cost_of_tuitioncostOfTuition = fnlMath
 academic_yearx += 1
academicYear1 = "${:,.append2f}".format(years[0])
academicYear2 = "${:,.2f}".format(fnlMathyears[1])
academicYear3 = "${:,.2f}".format(years[2])
academicYear4 = "${:,.2f}".format(years[3])
academicYear5 = "${:,.2f}".format(years[4])
academicYear1Inc1 = academic_year_inc"${:,.append2f}".format(tuitionIncrease[0])
academicYear1Inc2 = "${:,.2f}".format(intMathtuitionIncrease[1])
academicYear1Inc3 = "${:,.2f}".format(tuitionIncrease[2])
academicYear1Inc4 = "${:,.2f}".format(tuitionIncrease[3])
academicYear1Inc5 = "${:,.2f}".format(tuitionIncrease[4])
total_tuition_increaseSumtotalTuitionIncreaseSum = sum(tuition_increasetuitionIncrease)
total_tuition_increasetotalTuitionIncrease = "${:,.2f}".format(total_tuition_increaseSumtotalTuitionIncreaseSum)
4
print('UNDERGRADUATE TUITION FOR THE NEXT FIVE YEARS ')
print('ACADEMIC YEAR TUITION INCREASE ')
print('------------- ------------ -------- ')
for i, yearprint('2016-17 in enumerate(range(16, 21)):
 print('{}-{} ' + academicYear1 + ' {} ' + academicYear1Inc1) {}'.format
print(year'2017-18 + 2000, year + 1,
 ' + academicYear2 + ' ' + academicYear1Inc2) 
print('2018-19 ' + academicYear3 + ' ' + academic_year[i],academicYear1Inc3)
print('2019-20 ' + academicYear4 + ' ' + academicYear1Inc4)
print('2020-21 ' + academicYear5 + ' academic_year_inc[i]) ' + academicYear1Inc5)
print('TOTAL TUITION INCREASE ' + total_tuition_increasetotalTuitionIncrease)
RESIDENCY_COST = {
  "I": 10000,
 "O": 24000,
 "G": 40000,
 }

cost_of_tuition = None
while True:
 residency = raw_input('Please input your type of residency, I for in-state, O for out-of-state, and G for graduate: ')
 try:
 cost_of_tuition = RESIDENCY_COST[residency]
 break
 except ValueError:
 print ('Please enter I, G or O ONLY.')
 
years = []
tuition_increase = []
academic_year = []
academic_year_inc = []

for _ in range(5):
 intMath = cost_of_tuition * 0.03
 tuition_increase.append(intMath)
 fnlMath = intMath + cost_of_tuition
 years.append(fnlMath)
 cost_of_tuition = fnlMath
 academic_year.append("${:,.2f}".format(fnlMath))
 academic_year_inc.append("${:,.2f}".format(intMath))
total_tuition_increaseSum = sum(tuition_increase)
total_tuition_increase = "${:,.2f}".format(total_tuition_increaseSum)
print('UNDERGRADUATE TUITION FOR THE NEXT FIVE YEARS ')
print('ACADEMIC YEAR TUITION INCREASE ')
print('------------- ------------ -------- ')
for i, year in enumerate(range(16, 21)):
 print('{}-{} {} {}'.format(year + 2000, year + 1,
 academic_year[i],
 academic_year_inc[i]))
print('TOTAL TUITION INCREASE ' + total_tuition_increase)
inState = 10000
outState = 24000
profGrad = 40000

years = []
tuitionIncrease = []

i = raw_input('Please input your type of residency, I for in-state, O for out-of-state, and G for graduate: ')

if i == 'I':
 costOfTuition = inState
elif i == 'O':
 costOfTuition = outState
elif i == 'G':
 costOfTuition = profGrad

x = 0
while x != 5:
 intMath = costOfTuition * 0.03
 tuitionIncrease.append(intMath)
 fnlMath = intMath + costOfTuition
 years.append(fnlMath)
 costOfTuition = fnlMath
 x += 1
academicYear1 = "${:,.2f}".format(years[0])
academicYear2 = "${:,.2f}".format(years[1])
academicYear3 = "${:,.2f}".format(years[2])
academicYear4 = "${:,.2f}".format(years[3])
academicYear5 = "${:,.2f}".format(years[4])
academicYear1Inc1 = "${:,.2f}".format(tuitionIncrease[0])
academicYear1Inc2 = "${:,.2f}".format(tuitionIncrease[1])
academicYear1Inc3 = "${:,.2f}".format(tuitionIncrease[2])
academicYear1Inc4 = "${:,.2f}".format(tuitionIncrease[3])
academicYear1Inc5 = "${:,.2f}".format(tuitionIncrease[4])
totalTuitionIncreaseSum = sum(tuitionIncrease)
totalTuitionIncrease = "${:,.2f}".format(totalTuitionIncreaseSum)
4
print('UNDERGRADUATE TUITION FOR THE NEXT FIVE YEARS ')
print('ACADEMIC YEAR TUITION INCREASE ')
print('------------- ------------ -------- ')
print('2016-17 ' + academicYear1 + ' ' + academicYear1Inc1) 
print('2017-18 ' + academicYear2 + ' ' + academicYear1Inc2) 
print('2018-19 ' + academicYear3 + ' ' + academicYear1Inc3)
print('2019-20 ' + academicYear4 + ' ' + academicYear1Inc4)
print('2020-21 ' + academicYear5 + '  ' + academicYear1Inc5)
print('TOTAL TUITION INCREASE ' + totalTuitionIncrease)
Revised code for further editing. Added some suggested changes.
Source Link
Aaron
  • 357
  • 1
  • 4
  • 11
Loading
Add Python 2 tag since `raw_input` was used.
Link
ferada
  • 11.4k
  • 25
  • 65
Loading
edited tags
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
Loading
Source Link
Aaron
  • 357
  • 1
  • 4
  • 11
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /