76,983 views
4 votes
4 votes
PYTHON PROGRAMMING: At one college, the tuition for a full-time student is $8,000 per semester.

It has been announced that the tuition will increase by 3 percent each year for the next 5 years. Write a program with a loop that displays the projected semester tuition amount for the next 5 years. The program should print out the result in the form:
In 1 year, the tuition will be $8002.3.
In 2 years, the tuition will be $8103.2.In 3 years, …
In 4 years, …
In 5 years, …
(If, for example, the tuition would cost 8002.3 dollars in one year, etc.)
HERE'S WHAT I TRIED (wont show indentations here):
Semester_Fee = 8000.0
for x in range(1, 6):
Semester_Fee = Semester_Fee + (Semester_Fee *(3/(100*1.0)))
print("In",x,"year, the tuition will be" ,'$', Semester_Fee, end='.n')
BUT HERE'S WHAT IT SHOWED ME:
Expected Result:
In·1·year,·the·tuition·will·be·$8240.0.
In·2·years,·the·tuition·will·be·$8487.2.
In·3·years,·the·tuition·will·be·$8741.816.
In·4·years,·the·tuition·will·be·$9004.07048.
In·5·years,·the·tuition·will·be·$9274.192594400001.
Your Code's Actual Result:
In·1·year,·the·tuition·will·be·$·8240.0.
In·2·year,·the·tuition·will·be·$·8487.2.
In·3·year,·the·tuition·will·be·$·8741.816.
In·4·year,·the·tuition·will·be·$·9004.07048.
In·5·year,·the·tuition·will·be·$·9274.1925944.

User Thibaut Noah
by
3.0k points

1 Answer

2 votes
2 votes

Answer:

Try :

Semester_Fee = 8000.0

for x in range(1, 6):

import decimal

Semester_Fee = Semester_Fee + Semester_Fee *(3/(100*1.0))

if x==1:

print("In",x,"year, the tuition will be" ,'$', Semester_Fee, end='.')

else:

print("In",x,"years, the tuition will be" ,'$', Semester_Fee, end='.')

User Jef
by
2.7k points