# 4.11. Student scholarship problem¶

Note

The following discussion has been made into a Python
notebook `../ipython_notebooks/problem_solving/student_scholarship_problem.ipynb`

In isolation, none of the concepts we have learned up till now gets us very far. But used in combination these concepts provide us with tools of great power. This section tries to demonstrate this with a single example taken from the Intro to comp science MIT online course

A wealthy donor has given SDSU $500,000 to be used to pay the tuition of one student every other year until the money runs out. Under the assumptions that:

- The current annual tuition is $34,986 per year. (This problem was originally designed for a MIT tuition, and I have left this number alone. This number is no longer realistic for an MIT tuition, and alas, it is BECOMING realistic for a SDSU tuition!);
- Tuition goes up at a rate of 4.1 % per year; and
- The principal will be invested so that it earns 5 % per year,

Solve the following problem. Write a program that calculates and prints the total number of students this gift will support and the tuition paid for the last student. (Assume we support a student in the 0th year, the 2nd year, and so on…)

We are given the following **initial conditions**, which we place
in variables:

```
initial_balance = 500000
initial_tuition = 34986
no_students = 0
```

We assume the following **constants**:

```
tuition_rate_inc = pow(1.041,2) # Support every OTHER year.
investment_return = pow(1.05,2)
```

It will be helpful to have a function for printing out results:

1 2 3 4 5 | ```
def print_results(no_students, tuition, balance):
print 'No students: %d' % no_students
print 'Tuition: %.2f' % tuition
print 'Balance: %.2f' % balance
print
``` |

Now let’s use a *while* loop to start exploring:

1 2 3 4 5 6 7 8 | ```
while balance > tuition:
balance -= tuition
no_students += 1
tuition = (tuition * tuition_rate_inc)
balance = (balance * investment_return)
print 'Initial gift: %.2f' % initial_balance
print_results(no_students, tuition, balance)
``` |

Now consider the following problem:

1 2 3 4 5 6 7 | ```
Write a program that calculates and prints the smallest gift (rounded to
the nearest $100) needed to support one student every other year for 100
years. In addition, print the number of iterations your program took to
arrive at the answer. Hint 1: Use trial and error. Write a program
that detects when the initial gift is too small to solve the problem,
then increments it gradually until the gift is just big enough.
Hint 2: you may want to use nested loops for this problem.
``` |