04 Prepare : Checkpoint B
Objective
Demonstrate the use of multiple files in Python.
Overview
After completing (or while completing) the preparation material for this week, complete the following exercise.
Instructions
For this assignment, you are supplied with a file containing two working classes and a main function that tests them. Your job is to break this up into three files, one for each class and one for the main function.
The File Location
The file to begin with is found at:
/home/cs241/check04b.py
You should create a new directory and copy it to your directory as follows:
mkdir check04b
cd check04b
cp /home/cs241/check04b.py .
Please note the final "." in the copy command. It says, "copy it to my current directory."
The File Contents
This file contains a class for an address, and one for a credit card. The credit card contains two addresses, a mailing address and a billing address. Each class also contains a display function. The main function asks the user for some basic information, populates a credit card object and displays it.
You should create 3 files:
credit_card.py
address.py
main.py
main.py
should contain the main function and import the CreditCard
class from credit_card.py
. The file credit_card.py
should import the Address
class from address.py
Sample Output
The following is an example of output for this program:
Name: Mary
Number: 1234123412341234
Mailing Address:
Street: 123 North Str.
City: Rexburg
State: ID
Zip: 83440
Billing Address:
Street: 456 South Str.
City: Salt Lake City
State: UT
Zip: 84101
Mary
1234123412341234
Mailing Address:
123 North Str.
Rexburg, ID 83440
Billing Address:
456 South Str.
Salt Lake City, UT 84101
Testing and Submitting Multiple Files
The testBed and submit commands are written to only accept a single file. Because of this, in order to submit, we need to combine our separate python files into a single "tar" file, which is similar to a .zip file.
To create a new tar file named check04b.tar with all of the files for this assignment, go to your directory and run the following command:
tar -cf check04b.tar main.py credit_card.py address.py
Or, if we want to automatically include all the .py files in the current directory we could type:
tar -cf check04b.tar *.py
This "creates a file" (hence, cf) with the name of whatever comes after it. Then comes a list of all the files to include. The first line above includes each of the .py files one by one, the second version (using *.py) says, include all the .py files in the current directory.
Please note that you MUST include the name of a tar file, if you forget and write something like this:
THIS IS BAD: tar -cf *.py
It will assume that one of your .py files is the name that you want to use for your tar file, and overwrite it. Yikes!
Once you have a tar file, you can use it with testBed or submit, just like before:
testBed cs241/check04b check04b.tar
submit check04b.tar
The testBed and submit tools will un-tar the file, and then look for a file named main.py, which will then be run to execute the program.
Automatic Grading Script (TestBed)
This assignment is pass/fail. In order to receive credit, it must pass the auto-grading test script (TestBed). You can run this script as many times as you like while you are working on the assignment. The same test script will be run by the instructor for credit, so you should not be surprised at the result.
In addition, because the point of this exercise is to help you practice the use of classes. You must use classes to receive credit for this assignment.
To run the test script, log into the CS Department Linux system and run the testBed
command, providing the class and test script to run as well as the Python program to use, for example:
testBed cs241/check04b check04b.tar
Submission
Submit your program by logging into the CS Department Linux system, and running the submit command with your filename, for example:
submit check04b.tar
You should then select the appropriate course (CS 241), instructor, and assignment from the list.