1 Replies - 566 Views - Last Post: 07 March 2016 - 04:24 PM Rate Topic: -----

#1 Failing Calculus   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 07-March 16

Help with intro level CS code

Posted 07 March 2016 - 01:08 PM

Ive been banging my head against multiple issues with this code but I've finally got it down to one remaining problem. The calculations perform as intended (it looks ugly but i'm okay with that as long as it works) but the one remaining issue with the code is I do not know how to place commas in the thousandth position in the table at the end. I found a potential solution to this is "{:,}".format(value), however I do not understand how to fit that into my code. As it says in the intro I am a novice, so my first attempt looked like (format(year_2_inc, '.2f', {:,}))), but that gives format 3 arguments when it can only take two. My second attempt I thought, "hey I wonder if I can format a format" and tried (format(format(year_1_inc, '.2f')), "{:,}")) which obviously didn't work. Any help is appreciated.
My code looks as follows-

  
Residency = (input("Type of residency? 'I' for In-state, 'O' for out of state, 'G' for Graduate: "))

In_State = 10000

Out_Of_State = 24000

Graduate = 40000

if Residency == 'I':
    Tuition = In_State
    
elif Residency == 'O':
    Tuition = Out_Of_State
    
elif Residency == 'G':
    Tuition = Graduate
                    
            
year_1 = float(Tuition * .03 + Tuition)
year_1_inc = float(Tuition * .03)

year_2 = float(year_1 * .03 + year_1)
year_2_inc = float(year_1 * .03)

year_3 = float(year_2 * .03 + year_2)
year_3_inc = float(year_2 * .03)

year_4 = float(year_3 *.03 + year_3)
year_4_inc = float(year_3 * .03)

year_5 = float(year_4 * .03 + year_4)
year_5_inc = float(year_4 * .03)

    
print('UNDERGRADUATE TUITION FOR THE NEXT FIVE YEARS')

print('ACADEMIC YEAR',"       ",'TUITION',"       ",'INCREASE')

print("-------------", "       ","-------","       ","--------")

print ('2016-17' + '               ' + (format(year_1, '.2f')) + '        ' + (format(year_1_inc, '.2f')))

print ('2017-18' + '               ' + (format(year_2, '.2f')) + '        ' + (format(year_2_inc, '.2f')))

print ('2018-19' + '               ' + (format(year_3, '.2f')) + '        ' + (format(year_3_inc, '.2f')))

print ('2019-20' + '               ' + (format(year_4, '.2f')) + '        ' + (format(year_4_inc, '.2f')))

print ('2020-21' + '               ' + (format(year_5, '.2f')) + '        ' + (format(year_5_inc, '.2f')))

print ('TOTAL TUITION INCREASE' + '                ' + (format(year_1_inc + year_2_inc + year_3_inc + year_4_inc + year_5_inc, '.2f')))


This post has been edited by andrewsw: 07 March 2016 - 01:12 PM
Reason for edit:: fixed [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: Help with intro level CS code

#2 Failing Calculus   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 07-March 16

Re: Help with intro level CS code

Posted 07 March 2016 - 04:24 PM

All good now. I read up some more and found out it was pretty simple. I just needed to add a comma in front of '.2f', making it ',.2f'.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1