The goal of this lab assignment to allow you to explore conditional execution by writing interactive Python programs that utilize if, elif, and else statements.

For this assignment, record your work in a Jupyter Notebook and upload it to the form below by 11:59 PM Friday, February 8.

Activity 0: Starter Notebook

To help you get started, we have provided you with a starter notebook, which you can download and then use to record your answers. To utilize the starter notebook, download it to wherever you are running Jupyter Notebook and then use the Jupyter Notebook interface to open the downloaded file.

Download Starter Notebook

The starter notebook is already formatted for all the various sections you need to fill out. Just look for the red instructions that indicates were you need to write text or the cyan comments that indicate where you need to write code.

Activity 1: Letter Grade

For the first activity, you are to write a program that reports to the user their grade percentage and their letter grade given the total amount of points they have earned.

As you know from the course website, the class is out of a total of 300 points. Each assignment (readings, labs, etc.) contribute a certain number of points to the student's total. At the end of the semester, the student can determine their grade based on the following table:

Grade Points Grade Points Grade Points
A 280-300 A- 270-279
B+ 260-269 B 250-259 B- 240-249
C+ 230-239 C 220-229 C- 210-219
D 195-209 F 0-194

Given the number of points a student has accumulated, you are to report something like this:

>>> summarize_grade(280)
Grade of 280 / 300 is 93.33% (A)

Functions

To write this program, you will need to implement the following two functions:

MAX_POINTS = 300

def letter_grade(points):
    ''' Return letter grade based on given points. '''

def summarize_grade(points):
    ''' Display grade as percentage and letter ''

Here are some examples of the functions in action:

>>> letter_grade(250)
'B'

>>> summarize_grade(250)
Grade of 250 / 300 is 83.33% (B)

Interaction

Once you have implemented the functions above, you are to use the following interaction to test and examine your code:

>>> interact(summarize_grade, points=(0, 300))

This should produce an interactive widget that looks like this:

Reflection

After you have verified that your functions and interaction work, answer the following reflection questions:

  1. Describe the flow control of your program. Did you use alternative execution, chained conditionals, or nested conditionals?

  2. As programs become more complex, it is important to break programs down into smaller individual components such as functions. Discuss how having separate letter_grade and summarize_grade functions was useful in this program.

Activity 2: Stadium Seating

For the second activity, you are to write a program that helps visitors to Notre Dame stadium figure out the best gate to enter through for their specified section.

Your program should follow the gate assignments below:

Gate Sections
A 1, 2, 3, 4, 5, 6, 7, 8, 9, 101, 102, 103, 104, 105, 106, 107, 108, 109
B 10, 11, 12, 13, 14, 15, 16, 17, 18, 110, 111, 112, 113, 114, 115, 116, 117, 118
D 19, 20, 21, 22, 23, 24, 25, 26, 27, 119, 120, 121, 122, 123, 124, 125, 126, 127
E 28, 29, 30, 31, 32, 33, 34, 35, 36, 128, 129, 130, 131, 132, 133, 134, 135, 136

Given a section number, you are to report something like this:

>>> display_gate(10)
Seats in Section 10 should use Gate B

Functions

To write this program, you will need to implement the following two functions:

def find_stadium_gate(section):
    ''' Return the closest gate corresponding to the given stadium section. '''

def display_gate(section=0):
    ''' Display which gate seats in given section should use. '''

Here are some examples of the functions in action:

>>> find_stadium_gate(124)
'C'

>>> display_gate(124)
Seats in Section 124 should use Gate C

>>> find_stadium_gate(200)
# Returns None

>>> display_gate(200)
Invalid Section: 200

Interaction

Once you have implemented the functions above, you are to use the following interaction to test and examine your code:

>>> interact(display_gate, section='')

This should produce an interactive widget that looks like this:

Reflection

After you have verified that your functions and interaction work, answer the following reflection questions:

  1. Describe the flow control of your program. Did you use alternative execution, chained conditionals, or nested conditionals?

  2. A core part of building robust applications is having code that can handle errors such as invalid user input data. In this program, describe the ways in which you accounted for possible invalid data.

Submission

Once you have completed your lab, submit your Jupyter Notebook using the form:

Submit Lab Notebook