Winter 2024 Quiz 3

← return to practice.dsc10.com


This quiz was administered in-person. It was closed-book and closed-note; students were not allowed to use the DSC 10 Reference Sheet. Students had 20 minutes to work on the quiz.

This quiz covered Lectures 8-11 of the Winter 2024 offering of DSC 10.


Flights DataFrame

The DataFrame flights contains information about recent flights, with each row representing a specific flight and the following columns:


Problem 1

Suppose the function first_two takes as input a string and returns a string with the first two characters only. For example first_two("panda") is "pa". Using this function, write an expression that evaluates to a Series containing the two-character airline designator for each flight in flights.

Answer: flights.get("flight_num").apply(first_two)


Difficulty: ⭐️⭐️

The average score on this problem was 78%.


Problem 2


Problem 2.1

Fill in the blanks below so that grouped is a DataFrame showing how many flights on each airline departed from each airport.

    grouped = flights.groupby(___(x)___).___(y)___.get(['flight_num'])

Answer (x): ["departure", "airline"] or ["airline", "departure"]


Difficulty: ⭐️⭐️

The average score on this problem was 82%.

Answer (y): count()


Difficulty: ⭐️⭐️

The average score on this problem was 89%.


Problem 2.2

Suppose the expression grouped.shape[0] == flights.shape[0] evaluates to True. Select all true statements below.

Answer: Option 3 and Option 4


Difficulty: ⭐️⭐️

The average score on this problem was 80%.



Problem 3

Suppose we have another DataFrame more_flights which contains the same columns as flights, but different rows. Define merged as follows.

        merged = flights.merge(more_flights, on = "airline")

Suppose that in merged, there are 108 flights where the airline is "United", and in more_flights, there are 12 flights where the airline is "United". If flights has 15 rows in total, how many of these rows are not for "United" flights? Give your answer as an integer.

Answer: 6


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 64%.


Problem 4


Problem 4.1

Fill in the blanks below so that prob evaluates to the probability that a randomly selected flight from the flights DataFrame arrives at "SAN" given that it departs from "LAX".

san = flights.get("arrival") == "SAN"
lax = flights.get("departure") == "LAX"
prob = flights[san___(x)___lax].shape[0] / ___(y)___

Answer (x): &


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 66%.

Answer (y): flights[lax].shape[0]


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 62%.


Problem 4.2

Write an expression that evaluates to the probability that a randomly selected flight from the flights DataFrame is not on the airline "Delta".

Answer: 1 - flights[flights.get("airline") == "Delta"].shape[0] / flights.shape[0] or flights[flights.get("airline") != "Delta"].shape[0] / flights.shape[0] or (flights.get("airline") != "Delta").mean()



Problem 5

Use the function defined below to answer the questions on the right.

def discount(duration, price):
    if duration > 6:
        price = price * 0.9
    if duration > 4:
        price = price * 0.95 
    elif duration > 3:
        price = price * 0.98
    else:
        price = price * 0.99 
    price = price - 5 
    return price


Problem 5.1

What is the output of discount(7, 100)?

Answer: Option 2


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 72%.



Problem 5.2

Find x and y such that discount(x, y) evaluates to 97 * 0.98 - 5.

Answer (x): anything from the interval (3,4]


Difficulty: ⭐️

The average score on this problem was 95%.

Answer (y): 97


Difficulty: ⭐️

The average score on this problem was 95%.



👋 Feedback: Find an error? Still confused? Have a suggestion? Let us know here.