Reputation: 1
I have a problem I need to calculate future tuition depending on the input that the user puts. So for example the tuition is 5,000 per year and increases by 7% every year. If a user inputs 6 the program should print the total cost of tuition for years six, seven, eight and nine. So far I have this.
year = 1
n = int(input())
tuition = 5000
for i in range (n,n + 3):
tuition = tuition * 1.07
year = year + 1
print (tuition)
Upvotes: 0
Views: 214
Reputation: 27105
Regardless of what the user inputs, your for loop will run through 3 iterations.
It looks like you're trying to add a 7% increase (compound) every year for 3 years.
You don't need a loop for that.
e.g.,
tuition = 5_000
years = 3
increase = 1.07
print(tuition * increase ** years)
Output:
6125.215
Upvotes: 1
Reputation: 9228
The problem with your program is that you are looping using a for loop but you are not using the value i
within your for loop. You should use it. Additionally think about how many times your print()
statement is executed. Only once, but you need it for every year so think about moving it into the for loop as well.
One other thing: input()
takes a string as a parameter so you can provide some description of what a user is supposed to enter. You should use this as well to make your program usable.
n = int(input("Please enter a start year:"))
Upvotes: 0