Assignment 1

Goals

The goal of this assignment is to get acquainted with Python using Jupyter Notebooks.

Instructions

You will be doing your work in a Jupyter notebook for this assignment. You may choose to work on this assignment on a hosted environment (e.g. tiger) or on your own local installation of Jupyter and Python. You should use Python 3.13 for your work. (Older versions may work, but your code will be checked with Python 3.13.) To use tiger, use the credentials you received. If you work remotely, make sure to download the .ipynb file to turn in. If you choose to work locally, Anaconda, miniforge, or uv are probably the easiest ways to install and manage Python. If you work locally, you may launch Jupyter Lab either from the Navigator application (anaconda) or via the command-line as jupyter-lab or jupyter lab.

Due Date

The assignment is due at 11:59pm on Friday, September 5.

Submission

You should submit the completed notebook file required for this assignment on Blackboard. The filename of the notebook should be a1.ipynb.

Details

Please make sure to follow instructions to receive full credit. Use a markdown cell to Label each part of the assignment with a heading that includes the number of the section you are completing. You may put the code for each part into one or more cells.

0. Name & Z-ID (5 pts)

The first cell of your notebook should be a markdown cell with a line for your name and a line for your Z-ID. If you wish to add other information (the assignment name, a description of the assignment), you may do so after these two lines.

Hints
  • This Markdown cheatsheet may be useful.
  • New lines do not necessarily translate to new lines in Markdown. Use headings (#), lists (*), or paragraphs (empty line in between) to obtain a new line.

1. Hello, DeKalb (5 pts)

Write code that prints the following output. Note that there is an empty line between the first and third lines.

Hello,

DeKalb

2. Hello, <name> (10 pts)

Write code that assigns your name (a string) to a variable name, and then outputs

*****************
* Hello, <name> *
*****************

where <name> is replaced by the value of the variable. Thus, if you change the string assigned to the variable, the output should change. If name is "Eleanor", then the output would be

******************
* Hello, Eleanor *
******************

Note that the number of stars changes based on the number of characters in name. You can calculate the number of characters using in name using len(name), and you can create a string with n stars using '*' * n (python’s repetition operator). For a challenge (not required), generate this output in Jupyter without using any print statements or any other function calls besides len.

Hints
  • The print function allows multiple arguments and prints all of them with a space separating them.
  • You can also use python’s concatenation operator (+) with strings.

3. Calculating Annuities (20 pts)

An annuity is a financial product where you add or subtract the same amount of money every period, e.g., month or year, and earn a consistent interest rate at the end of every period. In an ordinary annuity, the money is added at the end of each period. A bank account with direct deposit is an example of an ordinary annuity. In an annuity due, the money is added at the beginning of the period. Rent is an example of an annuity due. The future value of an annuity is the amount of money you will have if you add \(C\) dollars per period, earn an interest rate of \(i\), and keep it invested for \(n\) periods. The present value of an annuity is how much money you need to have in order to have \(C\) dollars per period for \(n\) periods at a rate of \(i\). Thus, \(C\) is the cash flow per period, \(i\) is the interest rate and \(n\) is the number of payments.

Write code that calculates the results according to the four formulas related to annuities below. (Do not write functions for this assignment; just calculate according to the formulas.) First, create a cell that assigns the values (\(C = 1000\), \(i = .05\), \(n = 5\)) to the variables c, i, and n. Then, write four cells (one for each part) to calculate the formulas below. Make your code efficient. Assign the output to its corresponding variable (fv_ordinary, pv_ordinary, fv_due, and pv_due) and display the output of each formula’s calculation. Note that your formulas must use the variables c, i, and n; this will allow you to also check other values of those variables by changing their values and rerunning the formula cells. For example, you might go back to the first cell that assigns the values and change them to \(C = 2000\), \(i = .04\), \(n = 10\), and then recompute the next four cells. Turn in your code with the original values (\(C = 1000\), \(i = .05\), \(n = 5\)).

a. Future value of an ordinary annuity (5 pts)

\[ FVordinary(C, i, n) = C \times\ \left[\frac{(1+i)^n - 1}{i}\right] \]

b. Present value of an ordinary annuity (5 pts)

\[ PVordinary(C, i, n) = C \times\ \left[\frac{1-(1+i)^{-n}}{i}\right] \]

c. Future value of an annuity due (5 pts)

\[ FVdue(C, i, n) = C \times\ \left[\frac{(1+i)^n - 1}{i}\right] \times (1+i) \]

d. Present value of an annuity due (5 pts)

\[ PVdue(C, i, n) = C \times\ \left[\frac{1-(1+i)^{-n}}{i}\right] \times (1+i) \]

Hints
  • Remember order of operations
  • You can do the last two parts very efficiently using the principle of “don’t repeat yourself”!