CS 1

# Short Assignment : How Rich Am I?

Read the entire assignment before you start designing your program or writing any code.

In the year 0 A.D., my ancestor Brutus Balkcom deposited \$1.00 in the Bank of Rome. (OK, it wasn’t a real dollar; it was the Roman equivalent of a dollar. Probably some kind of big coin with a hole in the middle.) The bank promised to pay 5% interest compounded once a year.

In other words, they multiplied his balance by 1.05 once each year, so that

• at the end of the year 1 A.D., the balance was \$1.05.
• at the end of the year 2 A.D., the balance was \$1.1025 (which is 1.05 × 1.05).
• at the end of the year 3 A.D., the balance was \$1.157625 (which is 1.1025 × 1.05).

Since old Brutus was not around to withdraw it (Caesar’s descendants took care of that), the balance has accumulated nicely up to the present day. Because I am his rightful heir, the bank account is now mine. Bwa-ha-ha!!

## Problem 1

Your first job is to write a Python program that computes my current wealth: the balance of the account after 5% interest was compounded 2024 times. Your program should print my wealth a the end of the year 2024 and the total interest I earned in 2024 years.

## Problem 2

In a coincidence that defies the odds, our section leader Liz Brissie has an ancestor, Portia Brissie, who also deposited money in the Bank of Rome in the year 0 A.D.

Back then, the Brissie family was much better off than the Balkcom family, and Portia deposited \$100,000.00. But Portia did not know that in business, you don’t get what you deserve – you get what you negotiate – and she was able to get only a 4% interest rate on her deposit.

Your job is to write a Python program that computes the first year in which Brutus’s balance exceeds Portia’s balance, and prints out that year and the two balances in that year.

## What to do and how to do it

By convention, when we intend a variable’s value to never change, we write the name of the variable in all uppercase. We call a variable that should never change a constant. For example, if you wanted to have a variable indicating Brutus’s interest rate, you might define it with the code

BRUTUS_INTEREST_RATE = 5

(You don’t have to use this exact name or this exact value. I’m just providing it as an example of how we define constants in Python.)

Now, Python won’t prevent you from changing the value of a variable whose name is in all uppercase. It’s just a programming convention for the benefit of wetware (the stuff between your ears).

In this assignment, you should use constants (variable names in all uppercase) at the top of your program for the initial deposit amounts, interest rates, and – for Problem 1 – the current year. However, variables that change value should not be all uppercase. So for example, you might have a constant BRUTUS_INITIAL_DEPOSIT, but you might also have a variable brutus_wealth that keeps track of Brutus’s changing wealth over the years. In year 0, these might have the same value. In year 2024, these might have different values; but it’s nice to have the initial deposit amount still around in BRUTUS_INITIAL_DEPOSIT for the bank records, so that you could, for example compute how much Brutus earned in interest.

When you print out balances, they will be large. You will want to store them in floating point, and just let the floating point values print normally. (It’s fine if they print with scientific notation.) Your output should be nicely formatted. For example, if the current year were year 2 (not year 2024), the output of Problem 1 should read something like

At year 2, the balance is 1.1025.

Your output does not have to read exactly the same as mine, but it should read like an English sentence with spaces and punctuation in the right places. Remember that you can concatenate strings with the + operator, and you can convert a number to a string with Python’s str function. And, of course, you should program your solucdtion to Problem 1 to use the year 2024.

To compute the balances, use while-loops in which each iteration multiplies each balance by the appropriate factor. Do not use exponentiation to calculate balances. Start with the appropriate balances, and use loops to repeatedly multiply the balances by the appropriate amounts each time. Each iteration should correspond to one year.

Submit your programs for the two problems, along with runs that show the answers.

## A helpful hint

I found it quite helpful, when developing my programs, to include a print statement within the body of the loop to show the year and the balances in each iteration of the loop. That way, I could verify that my program was doing the right thing. I then removed the print statement from my loop before declaring my program complete. Of course, I left in a print call after the loop, to print the answer. You should consider doing the same thing, but make sure to remove the print call within the loop body—alternatively, you can leave it in but comment it out—before submitting your program and its output.

## What to turn in

1. how_rich.py (or whatever you called the program for Problem 1).
2. portia.py (or whatever you called the program for Problem 2).
3. A screenshot to show the output of running how_rich.py.
4. A screenshot to show the output of running portia.py.

Please remember in all assignments that editing the output of the program before printing it is a violation of the Academic Honor Principle. Make sure that the output you turn in comes from the program that you turn in. If you make any change to the code, no matter how insignificant you think it might be, rerun your program to produce new output!

Submit your assignment via Canvas.

## How to get help

You can post a note on Ed Discussion. Please do not include any code; ask your question in English. If that doesn’t work, write a polite note to your section leader asking for a hand. You are also welcome to ask the TA or professor for suggestions or visit their office hours.

## Honor Code

The consequences of violating the Honor Code can be severe. Please always keep in mind the word and spirit of the Honor Code.