0

Why are my loop calculations doubling?

I need to calculate tuition rates that increase 2% every year, over the course of five years... I wrote my code: def main(startyear, endyear): Tuition=6000 For Year in range (startyear, endyear): If Year==1: Tuition=6000 Else: Tuition=(Tuition+(Tuition*.02)) print(.......) main(1, 6) Any idea as to why my calculations keep doubling an extra 2.4% after the first 2 years??

20th Feb 2017, 5:42 PM
auri
auri - avatar
2 Respostas
+ 2
Because it's the way math works. You get 6120 after second loop iteration and then multiply the tuition (which is 6120) by 1.02, so you get 6242.4
20th Feb 2017, 5:53 PM
Zilvinas Steckevicius
Zilvinas Steckevicius - avatar
+ 1
Duh! Thank you! Ultimate brain fart
20th Feb 2017, 5:54 PM
auri
auri - avatar