Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote this code below and when I try the following test case get_certification('2015-01-14T08:00:00','S00313') I get the following message get_certification marked S00313 as 'STUDENT' on

I wrote this code below and when I try the following test case get_certification('2015-01-14T08:00:00','S00313') I get the following message

get_certification marked S00313 as 'STUDENT' on 2015-01-14T08:00:00, but was really 'NOVICE'.

I'm not sure how to fix this the definition of novice

  • PILOT_NOVICE (A pilot that has joined the school but has not soloed)

I took a screenshot of my csv file and highlighted in yellow the student the error message shows

image text in transcribed

import utils from datetime import datetime, timedelta

# 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 is 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 Parameter student: The student pilot Precondition: student is 10-element list of strings representing a pilot """ CERT = PILOT_INVALID

if (student[3] == "" or student[3] == None): return CERT else: timeline = utils.str_to_time(student[3], takeoff) if timeline != None and timeline >= takeoff: return CERT else: CERT = PILOT_NOVICE if (student[4] == "" or student[4] == None): return CERT else: timeline = utils.str_to_time(student[4], takeoff) if timeline != None and timeline >= takeoff: return CERT else: CERT = PILOT_STUDENT if (student[5] == "" or student[5] == None): return CERT else: timeline = utils.str_to_time(student[5], takeoff) if timeline != None and timeline >= takeoff: return CERT else: CERT = PILOT_CERTIFIED if (student[6] == "" or student[6] == None): return CERT else: timeline = utils.str_to_time(student[6], takeoff) if timeline != None and timeline >= takeoff: return CERT else: CERT = PILOT_50_HOURS

return CERT

utils file is as follows this function is correct

def str_to_time(timestamp,tz=None): """ Returns the datetime object for the given timestamp (or None if stamp is invalid) This function should just use the parse function in dateutil.parser to convert the timestamp to a datetime object. If it is not a valid date (so the parser crashes), this function should return None. If the timestamp has a timezone, then it should keep that timezone even if the value for tz is not None. Otherwise, if timestamp has no timezone and tz if not None, this this function will assign that timezone to the datetime object. The value for tz can either be a string or a time OFFSET. If it is a string, it will be the name of a timezone, and it should localize the timestamp. If it is an offset, that offset should be assigned to the datetime object. Parameter timestamp: The time stamp to convert Precondition: timestamp is a string Parameter tz: The timezone to use (OPTIONAL) Precondition: tz is either None, a string naming a valid time zone, or a time zone OFFSET. """ # HINT: Use the code from the previous exercise and update the timezone # Use localize if timezone is a string; otherwise replace the timezone if not None try: timestamp_str = timestamp timestamp = parse(timestamp) if (timestamp.tzinfo == None and tz != None): if tz in pytz.all_timezones: timestamp = timezone(tz).localize(timestamp) # print(timestamp) elif isinstance(tz, tzinfo): timestamp = add_tz_to_time(timestamp, tz) else: time2 = parse(tz) timestamp = add_tz_to_time(timestamp, time2.tzinfo) return timestamp

except: return None

. students QS00313 Formulas Data Review View AutoSum - 12 A- A- t> Wrap Text Date T Home Insert Page Layout X Cut Calibri (Body) Copy + Paste Format E6 . *fx 3/2/2015 Fill $ = == Merge & Center 2 . . Cell Styles Insert Delete Conditional Format Formatting as Table Format Clear 50 HOURS INSTRUMENT ADVANCED MULTIENGINE 1 ID 2 S00304 3 500308 4 S00309 5 S00311 6 S00313 7 S00314 B 500315 9 S00319 10 500321 11 S00224 12 500326 13 S00328 14 S00329 15 S00331 16 S00335 17 S00336 18 S00337 19 500341 20 S00342 21 500343 22 S00347 23 500350 24 S00352 25 S00353 26 500354 27 S00358 28 500362 LAST NAME FIRST NAME JOINED SOLO LICENSE Wilson Zachary 1/7/15 3/24/15 Bates Ashley 1/9/15 4/14/15 Jones Tammy 1/10/15 3/30/15 Wheeler Michael 1/14/15 4/8/15 Kelley Julie 1/14/15 3/2/15! Barrett Tammy 1/18/15 6/13/15 Murray Donald 1/20/15 B/29/15 Holland Tiffany 1/25/15 3/9/15 Coleman Judith 1/28/15 7/5/15 Morena Harold 1/29/15 4/11/15 Aguilar Jacob 1/31/15 3/27/15 Pearson Ethan 2/10/15 3/30/15 Carpenter Martha 2/10/15 9/12/15 Wilson Ruth 2/20/15 2/14/16 Campbell Ronald 2/21/15 4/10/15 Murphy Deborah 2/22/15 B/16/15 Reid Ralph 2/24/15 5/7/15 Torres Harold 2/24/15 4/10/15 Marshall Emma 2/24/15 10/25/15 Richards Sean 3/2/15 11/7/15 Dixon Sean 3/4/15 6/2/15 Dixon Henry 3/4/15 5/28/15 8/11/15 Munaz Louis 3/9/15 8/1/15 Pena Christopher 3/11/15 4/29/15 6/5/15 Morales Ray 3/15/15 4/30/15 Schultz Louis 3/15/15 3/6/16 Kim Nathan 3/16/15 6/23/15 8/11/15 12/22/15 12/22/15 9/8/15 1/5/16 . students QS00313 Formulas Data Review View AutoSum - 12 A- A- t> Wrap Text Date T Home Insert Page Layout X Cut Calibri (Body) Copy + Paste Format E6 . *fx 3/2/2015 Fill $ = == Merge & Center 2 . . Cell Styles Insert Delete Conditional Format Formatting as Table Format Clear 50 HOURS INSTRUMENT ADVANCED MULTIENGINE 1 ID 2 S00304 3 500308 4 S00309 5 S00311 6 S00313 7 S00314 B 500315 9 S00319 10 500321 11 S00224 12 500326 13 S00328 14 S00329 15 S00331 16 S00335 17 S00336 18 S00337 19 500341 20 S00342 21 500343 22 S00347 23 500350 24 S00352 25 S00353 26 500354 27 S00358 28 500362 LAST NAME FIRST NAME JOINED SOLO LICENSE Wilson Zachary 1/7/15 3/24/15 Bates Ashley 1/9/15 4/14/15 Jones Tammy 1/10/15 3/30/15 Wheeler Michael 1/14/15 4/8/15 Kelley Julie 1/14/15 3/2/15! Barrett Tammy 1/18/15 6/13/15 Murray Donald 1/20/15 B/29/15 Holland Tiffany 1/25/15 3/9/15 Coleman Judith 1/28/15 7/5/15 Morena Harold 1/29/15 4/11/15 Aguilar Jacob 1/31/15 3/27/15 Pearson Ethan 2/10/15 3/30/15 Carpenter Martha 2/10/15 9/12/15 Wilson Ruth 2/20/15 2/14/16 Campbell Ronald 2/21/15 4/10/15 Murphy Deborah 2/22/15 B/16/15 Reid Ralph 2/24/15 5/7/15 Torres Harold 2/24/15 4/10/15 Marshall Emma 2/24/15 10/25/15 Richards Sean 3/2/15 11/7/15 Dixon Sean 3/4/15 6/2/15 Dixon Henry 3/4/15 5/28/15 8/11/15 Munaz Louis 3/9/15 8/1/15 Pena Christopher 3/11/15 4/29/15 6/5/15 Morales Ray 3/15/15 4/30/15 Schultz Louis 3/15/15 3/6/16 Kim Nathan 3/16/15 6/23/15 8/11/15 12/22/15 12/22/15 9/8/15 1/5/16

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions