Skip to main content

Assignment07 Knowledge Document


Intro to Programming (Python)
Assignment 07 Knowledge Document

I. Overview

A. The “try/except” part of this assignment seemed pretty straight forward. I immediately thought of the previous arithmetic script where I tested the divisor for zero. For this assignment, instead of testing for zero I used try/except where I wrote the except clause as “except ZeroDivisionError:”  The result was as follows:
#
# Flag zero divide exception
try:
print("\nN1/N2 = ",N1/N2)
except ZeroDivisionError:
print("\nN1/N2 is indeterminate since N2 = 0")

B. The Pickling part of this assignment was more challenging. I wanted to make the resulting script more interesting than simply save and restore. So, I decided to create a list of dictionaries, where the key for each dictionary was a 4 character aircraft type code and the value was a list containing the wing span and the max landing weight of the aircraft. This data structure could easily be set up to include dozens of aircraft, but I chose to use only 4 types. The data structure which I “pickled” and them retrieved as needed was:
#
# define Aircraft Specs: type, span(m), MLW(kg/1000)
AC_Specs = [{'B747':['68.5','312.1']}, \
{'B767':['47.6','136.1']}, \
{'B777':['60.9','208.7']}, \
{'B787':['60','172.4']}]

I used a while loop to give the script user an opportunity to retrieve the specs of an aircraft of interest.

Note - The look/feel and user interaction for both scripts were initially far from what I was happy with. Numerous trial and error iterations were required before I was satisfied with the way the scripts behaved.

  
II. Examples

A. Command line view of the try/except script:






















B. Command line view of the “pickle” script:




















III. Access to the completed script for Assignment #7

As specified as part of the assignment, the code for each script was uploaded to GitHub. The scripts may be found in https://github.com/lastduxson. They are called Try_Except and AC_Pickle and are stored in a repository called “Early-Python-Code”.
This knowledge document can be found at the blog: rerlearningpython.blogspot.com.

Comments