151k views
1 vote
Write a recursive program that calculates the total tuition paid over certain number of years. The tuition goes up by 2.5% per year. This method does not return any value. It displays the information and here is the call to the method and the sample output.

User Sura
by
5.1k points

1 Answer

4 votes

Answer:

The program is as follows:

def calctuit(pay,n,yrs):

if n == 0:

return

pay*=(1.025)

print("Year ",yrs,": ",pay)

calctuit(pay,n-1,yrs+1)

n = int(input("Years: "))

pay = float(input("Tuition: "))

yrs = 1

calctuit(pay,n,yrs)

Step-by-step explanation:

The function begins here

def calctuit(pay,n,yrs):

This represents the base case

if n == 0:

return

This calculates the tuition for each year

pay*=(1.025)

This prints the tuition

print("Year ",yrs,": ",pay)

This calls the function again (i.e. recursively)

calctuit(pay,n-1,yrs+1)

The function ends here

This gets the number of years

n = int(input("Years: "))

This gets the tuition

pay = float(input("Tuition: "))

This initializes the years to 1

yrs = 1

This calls the function

calctuit(pay,n,yrs)

User Laure D
by
6.5k points