Question
Could you help me fix my code, please? def discover_violations(directory,output): Searches the dataset directory for any flight lessons the violation regulations. This function will
Could you help me fix my code, please?
def discover_violations(directory,output):
"""
Searches the dataset directory for any flight lessons the violation regulations.
This function will call list_weather_violations() to get the list of weather violations.
If list_endorsment_violations (optional) is completed, it will call that too, as
well as list_inspection_violations.It will concatenate all of these 2d lists
into a single 2d list of violations (so a flight may be listed more than once for
each of the three types of violations).
If the parameter output is not None, it will create the CSV file with name output
and write the 2d list of violations to this file.This CSV file should have the
following header:
STUDENT,AIRPLANE,INSTRUCTOR,TAKEOFF,LANDING,FILED,AREA,REASON
Regardless of whether output is None, this function will print out the number of
violations, as follows:
'23 violations found.'
If no violations are found, it will say
'No violations found.'
Parameter directory: The directory of files to audit
Precondition: directory is the name of a directory containing the files 'daycycle.json',
'weather.json', 'minimums.csv', 'students.csv', 'teachers.csv', 'lessons.csv',
'fleet.csv', and 'repairs.csv'.
Parameter output: The CSV file to store the results
Precondition: output is None or a string that is a valid file name
"""
pass# Implement this function
list_weather_violations = list_weather_violations(directory)
list_endorsement_violations = list_endorsement_violations(directory)
list_inspection_violations = list_inspection_violations(directory)
total_len = len(list_weather_violations) + len(list_endorsement_violations) + (list_inspection_violations)
final_list = []
if total_len == 0:
print('No violations found.')
return final_list
print(str(total_len) + ' violations found.')
header = ["STUDENT","AIRPLANE","INSTRUCTOR","TAKEOFF","LANDING,FILED","AREA","REASON"]
final_list = []
for l in list_weather_violations:
final_list.append(l)
for l in list_endorsement_violations:
final_list.append(l)
for l in list_inspection_violations:
final_list.append(l)
with open(output, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(final_list)
return final_list
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started