CS0008 Assignment 1

Introduction

The purpose of this assignment is to give you practice writing functions and programs. With the exception of month (which may take some time to figure out), the functions/program are straightward. The focus in this first assignment is to create well formed, well documented, well tested functions/programs which follow the specifications, are correct, and which produce good output.

This must be your own individual work. Do not look at anyone else's solution (or even part of it), and do not let anyone else look at yours (or even part of it). You should figure out the solutions by yourself; i.e., don't ask anyone how to solve the problem. It is fine to ask questions about Python itself, however.

Part 1: Writing functions

Write the following functions.

Work on the functions one by one. For each one, decide on test cases before you begin to write. Be sure to include a docstring for each function.

After you are done verifying your functions, put them and any extra functions you write into one file, called functions.py. This is the file you will submit.

Function Name Description
typing_speed(words, seconds) Given an integer (with value at least 0) indicating a number of words typed and another integer (with value at least 1) indicating the number of seconds it took to type that many words, return the typing speed, in words per minute (as a float).
remove_rightmost_digit(num) Given an integer (with value at least 0), return it but with the rightmost digit removed. If it has only one digit, return 0
get_rightmost_digit(num) Given an integer (with value at least 0), return its rightmost digit.
month(code) Given an string representing a date in yymmdd format, return the month number, an int between 1 and 12. (Hints: You don't need to use strings for this. Convert 'code' into an int. Call the two functions above.) This function may take you a while to figure out.

Part 2: Writing a program

This part of the assignment will give you experience putting together an entire program. Write a program in a file called auto_costs.py that asks the user to enter the following automobile costs: loan payment, insurance, gas, oil, and maintenance. The user should also be asked to indicate how often per year each cost is incurred (e.g., loan payments and gas are typically monthly costs and thus are incurred 12 times per year; insurance is typically a bi-annual cost and thus is incurred 2 times per year). However, people's situations may vary, so you should assume any cost could recur any number of times per year, from 1 to 12.

All costs are floating point values. Your program should print informative prompts (e.g., "Enter the amount you pay for insurance in the form xx.yy ". "Now please enter the number of times per year this cost is incurred.")

Once you have input all the information, your program should calculate and print out the total monthly costs and the total annual costs. The cost outputs should look good, e.g., $3,432.98.

Grading

These are the aspects of your work that we will focus on in the grading:

What to Hand In

Hand in the following files:

Submission instructions will be added soon.