Part I: The Assignment Files
One of the most important outcomes of this assignment is that you understand the importance of testing. This assignment will follow an iterative development cycle. That means you will write a few functions, then fully test them before you write any more. This process makes it easier to find bugs; you know that any bugs must have been part of the work you did since the last test.
Iterative development requires that you work on each of the files simultaneously. In particular, you will write some code in a1test.py, move to a1.py and then back to a1test.py. Therefore, to get you started we want you to first create all three files. You are not going to put (much) code in the files right now. We just want you to have the files created so that you have a starting point to work from.
The very first thing you should do is specifically create a directory for this assignment. This folder should contain the three assignment files and nothing else.
Part II: The Core Functions
Iterative Development
In this part of the assignment, you will work on the files a1.py and a1test.py. It is is broken into four parts (listed as Parts A, B, C, and D). In each part, you will do the following:
Write a function header into a1
We will give you the header to write. We will also give you a detailed docstring specification for the function. You should copy-and-paste the specification into the function body, indented.
Add test cases to a1test
Yes, this means you are writing tests before writing the function bodies. We talked about this in lecture.
Unless otherwise instructed, each test case should be a call to an assert function in the introcs module. Furthermore, your tests should be
representative. While we talked about this in class, you might be a little unsure of what we are asking for here. If so, you might want to go over
lab9 with a consultant before going any further.
Write the function bodies
Make sure that the function satisifies the specifications exactly. If the specification says to return something, you need a return statement. Make sure that the value returned is of the correct type.
Run the unit test a1test
If errors are found, fix them and re-test. Keep doing this until no more errors are found.
Function Specifications
The descriptions that we provide in each part below represent the level of completeness and precision we are looking for in your docstring comments. In fact, it is best to copy-and-paste these descriptions to create the first draft of your docstring comments. If you do not cut and paste, please adhere to the conventions we use, such as using a single line, followed by a blank line and a more descriptive paragraph, or by using "Returns: ..." for fruitful-functions. While we have provided the contents of the specification, we have not always formatted them properly for you.
Part III: The Application Script
You are essentially done. The last part of the assignment is to complete the file a1app.py. This file will be no more complicated than the script
die.py that you made for lab 5. In fact, it will have a similar number of lines.
At the top of the file a1app.py remember to add the line
import a1
This will allow you to access the exchange function in this script. This is the only function of a1.py that you will need to use. Everything else will be either an input function, a print function, or some other built-in function, just as you did in the lab.
We are not going to give you much more guidance than that. Use your file dice.py as a guide if you are unsure what to do. In this end, the script should prompt the user and provide an answer, as shown below.
[user@machine]:a1 > python a1app.py
3- letter code for original currency: USD 3-letter code for the new currency: EUR Amount of the original currency: 2.5
You can exchange 2.5 USD for 2.158923 EUR.
Obviously you will get different answers for different currencies and amounts. But otherwise, the output displayed must look exactly like it does above. You must use those exact words for your final print statement and end with a period.
Attachment:- cs assignment.rar