Quiz 2 – Catching Errors & Sorting
Graded Quiz • 10 min Quiz5 Questions Week 1
Re⥃askly Logo

Quiz 2 – Catching Errors & Sorting

Graded Quiz • 10 min Quiz5 Questions Week 1
Practice More Quizzes:
Quiz
Quiz
Quiz
5 Questions Week 3
Quiz
6 Questions Week 3

Q:

There is a flights.csv file containing the following content. Airline Number,Departure,Destination,Date,Price 1,A1234,Philadelphia,San Diego,2020-02-14,500 2,A12345,Philadelphia,Los Angeles,2020-02-14,1000 3,A123456,Philadelphia,New York,2020-02-14,1000 … You want to find all the flights that departed from Philadelphia and arrived in Los Angeles, for a price that is less than $1200. You already have the following script. import csv flights = [] with open(‘flights.csv’, ‘r’) as csvfile: reader = csv.DictReader(csvfile) for row in reader: flights.append(row) Which of the scripts below is true for getting the information mentioned above?

Q:

What is the result of the following script? f = lambda x: x * 4 print(f(2))

Q:

There is a MOOC.csv file containing the following content. id,name,height,weight,age 1,Melanie,72,130.6,30 2,Keenan,84,197.6,31 3,Tom,78,180.0,27 … You want to get the following filtered information for the students. import csv students = [] with open(‘MOOC.csv’, ‘r’) as csvfile: reader = csv.DictReader(csvfile) for row in reader: students.append(row) filtered_students = [row for row in students if int(calculate(row[“weight”], row[“height”])) < 2] The following script is developed by another student who wants to test whether it can catch the ValueError, because there are a lot of rows in MOOC.csv file and they may contain unexpected values. Which of the statements below is true for the following script? def calculate(str1, str2): calculated_number = 0 num1 = float(str1) num2 = float(str2) try: calculated_number = num1 / num2 except ValueError: print (‘Error!’) return calculated_number print(calculate(‘one’, ‘zero’))

Q:

We have the following information about students. student_info = [{‘first name’:’Caroline’, ‘last name’:’Harrison’, ‘birthdate’:’1997-03-02′}, {‘first name’:’Rachel’, ‘last name’:’Reynolds’, ‘birthdate’:’1996-01-07′}, {‘first name’:’Olivia’, ‘last name’:’James’, ‘birthdate’:’1998-05-09′}]

Q:

We have the following information about students. student_info = [{‘first name’:’Caroline’, ‘last name’:’Harrison’, ‘birthdate’:’1997-03-02′}, {‘first name’:’Rachel’, ‘last name’:’Reynolds’, ‘birthdate’:’1996-01-07′}, {‘first name’:’Olivia’, ‘last name’:’James’, ‘birthdate’:’1998-05-09′}]

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Find Questions in This Page: "CTRL+F"