SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.loops
Exercise:
Programming Excercises
Question:9 | ISBN:978013274719 | Edition: 6

Question

(Financial application: compute future tuition) Suppose that the tuition for a university  is $10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost of four years’ worth of tuition starting ten years from now.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Financial application: compute future tuition Program code:

 

# Initialize the variables
tuitionFee = 10000
annualIncrease = 0.05

# Calculate the tuitionFee in ten years
for _ in range(10):
    tuitionFee += tuitionFee * annualIncrease

# Calculate the total cost of four years' worth of tuitionFee starting ten years from now
totalCost = 0
for _ in range(4):
    totalCost += tuitionFee
    tuitionFee += tuitionFee * annualIncrease

# Display the results
print("Tuition Fee in ten years:", tuitionFee)
print("Total cost of four years' worth of tuition starting ten years from now:", totalCost)

 

Executed Output:

Tuition Fee in ten years: 19799.31599439397
Total cost of four years' worth of tuition starting ten years from now: 70207.39453239119

 

 

0 0

Discussions

Post the discussion to improve the above solution.