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:
.functions
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:

tuition = 10000  # Initial tuition
increaseRate = 0.05  # Annual tuition increase rate

# Compute the tuition in ten years
for _ in range(10):
    tuition += tuition * increaseRate

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

# Display the results
print("The tuition in ten years will be:", tuition)
print("The total cost of four years' worth of tuition starting ten years from now will be:", totalCost)

Executed Output:

The tuition in ten years will be: 19799.31599439397
The total cost of four years' worth of tuition starting ten years from now will be: 70207.39453239119

 

0 0

Discussions

Post the discussion to improve the above solution.