Question: Can you help me figure out implementing the get_certification function below using Python? The purpose of the function get_certification. Its arguments are a student (a
Can you help me figure out implementing the get_certification function below using Python?
The purpose of the function get_certification. Its arguments are a student (a single row in students.csv) and a takeoff time (a datetime object with a time zone). It returns the certification of that student at the time of takeoff. These certifications are indicated by one of the following variables defined in pilots.py:
PILOT_INVALID (A pilot that is not even in the school)
PILOT_NOVICE (A pilot that has joined the school but has not soloed)
PILOT_STUDENT (A pilot that has soloed but does not have a license)
PILOT_CERTIFIED (A pilot that has a license but has under 50 hours)
PILOT_50_HOURS (A pilot with 50 hours post license)
"""
Module determining pilot certifications, ratings, and endorsements.
The restrictions that we place on a pilot depend on their qualifications. There are three
ways to think about a pilot.
(1) Certifications. These are what licenses a pilot has. We also use these to classify
where the student is in the licensing process. Is the student post solo (can fly without
instructor), but before license? Is the student 50 hours past their license (a threshold
that helps with insurance)?
(2) Ratings. These are extra add-ons that a pilot can add to a license. For this project,
the only rating is Instrument Rating, which allows a pilot to fly through adverse weather
using only instruments.
(3) Endorsements. These are permission to fly certain types of planes solo. Advanced
allows a pilot to fly a plane with retractable landing gear. Multiengine allows a pilot
to fly a plane with more than one engine.
The file pilots.csv is a list of all pilots in the school, together with the dates that
they earned these certifications, ratings, and endorsements. Specifically, this CSV file
has the following header:
ID LASTNAME FIRSTNAME JOINED SOLO LICENSE 50 HOURS INSTRUMENT ADVANCED MULTIENGINE
The first three columns are strings, while all other columns are dates.
The functions in this class take a row from the pilot table and determine if a pilot has
a certain qualification at the time of takeoff. As this program is auditing the school
over a course of a year, a student may not be instrument rated for one flight but might
be for another.
The preconditions for many of these functions are quite messy. While this makes writing
the functions simpler (because the preconditions ensure we have less to worry about),
enforcing these preconditions can be quite hard. That is why it is not necessary to
enforce any of the preconditions in this module.
"""
import utils
# CERTIFICATION CLASSIFICATIONS
# The certification of this pilot is unknown
PILOT_INVALID = -1
# A pilot that has joined the school, but has not soloed
PILOT_NOVICE = 0
# A pilot that has soloed but does not have a license
PILOT_STUDENT = 1
# A pilot that has a license, but has under 50 hours post license
PILOT_CERTIFIED = 2
# A pilot that 50 hours post license
PILOT_50_HOURS = 3
def get_certification(takeoff,student):
"""
Returns the certification classification for this student at the time of takeoff.
The certification is represented by an int, and must be the value PILOT_NOVICE,
PILOT_STUDENT, PILOT_CERTIFIED, PILOT_50_HOURS, or PILOT_INVALID. It is PILOT_50_HOURS
if the student has certified '50 Hours' before this flight takeoff. It is
PILOT_CERTIFIED if the student has a private license before this takeoff and
PILOT_STUDENT if the student has soloed before this takeoff. A pilot that has only
just joined the school is PILOT_NOVICE. If the flight takes place before the student
has even joined the school, the result is PILOT_INVALID.
Recall that a student is a 10-element list of strings. The first three elements are
the student's identifier, last name, and first name. The remaining elements are all
timestamps indicating the following in order: time joining the school, time of first
solo, time of private license, time of 50 hours certification, time of instrument
rating, time of advanced endorsement, and time of multiengine endorsement.
Parameter takeoff: The takeoff time of this flight
Precondition: takeoff is a datetime object with a time zone
Parameter student: The student pilot
Precondition: student is 10-element list of strings representing a pilot
"""
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
