Assignment 1 - Hello, Python!

Due: Friday, January 10, 2020, at the start of class

You may work alone or with a partner, but you must type up the code yourself. You may also discuss the assignment at a high level with other students. You should list any student with whom you discussed the assignment, and the manner of discussion (high-level, partner, etc.) in a readme.txt file that you include with your submission.

You should submit your assignment as a .zip file on Moodle.

Problem 1: Hello, user!

# You should be equipped to complete this problem after lesson 1 (Monday Jan. 6).

For this problem, you should write a program that asks the user for their first and last name, and then greets them by name. Make sure to save your program as a .py file in IDLE (you can use File -> New File to get to the file editor from the shell).

Here is an example output trace:

Hello there!
What is your first name? Colin
What is your last name? Amert

Have a great day, Colin Amert

Problem 2: Calculating periodic interest

For this problem, you will modify the futval.py program from Zelle section 2.7. Note that I’ve replaced eval with int and float, as appropriate.

# futval.py
#    A program to compute the value of an investment
#    carried 10 years into the future.

def main():
    print("This program calculates the future value")
    print("of a 10-year investment.")

    principal = int(input("Enter the initial principal: "))
    apr = float(input("Enter the annual interest rate: "))

    for i in range(10):
        principal = principal * (1 + apr)

    print("The value in 10 years is:", principal)

main()

2a: User-provided number of years

# You should be equipped to complete this sub-problem after lesson 1 (Monday Jan. 6).

Modify the futval.py program to have the number of years be given as user input. Make sure to change the comments and printed messages accordingly.

Here is an example output trace:

This program calculates the future value
of a user-specified-year investment.
Enter the initial principal: 100
Enter the annual interest rate: 0.035
Enter the number of years: 20
The value in 20 years is: 198.97888634658423

2b: An alternative to APR

# You should be equipped to complete this sub-problem after lesson 2 (Wednesday Jan. 8).

As an alternative to APR, the interest accured on an account is often described in terms of a nominal rate and the number of compounding periods. For example, if the interest rate is 3% and the interest is compounded quarterly, the account actually earns 34% interest every three months.

Copy futval.py into a new file called futvalperiodic.py. In this file, modify the original program to use this periodic method of entering the interest rate. The program should prompt the user for the yearly rate (rate), the number of times that the interest is compounded each year (numPeriods), and the number of years (years) for the investment. To compute the value in years years, the program should loop years * numPeriods times and accrue rate/numPeriods interest on each iteration.

Edit: the rate here is the apr in the original program above.

Here is an example output trace compounding quarterly:

This program calculates the future value
of a user-specified-year investment.
Enter the initial principal: 100
Enter the annual interest rate: 0.035
Enter the number of years: 20
Enter the number of times to compound each year: 4
The value in 20 years is: 200.76306550073622

Here is another compounding monthly:

This program calculates the future value
of a user-specified-year investment.
Enter the initial principal: 100
Enter the annual interest rate: 0.035
Enter the number of years: 20
Enter the number of times to compound each year: 12
The value in 20 years is: 201.170203490801

What you should submit

You should submit a single .zip file on Moodle. It should contain the following files:

  • readme.txt (collaboration statement listing collaborators and form of collaboration)
  • greeting.py (problem 1)
  • futval.py (problem 2a)
  • futvalperiodic.py (problem 2b)

An example readme.txt file might be the following:

For this assignment, I collaborated with:
* Colin - partner
* Therese - discussed how to save a .py file from IDLE
* Piazza - why the alternative APR is 3/4 % interest

If you did not collaborate with anyone, you should say so:

For this assignment, I worked alone.