# Winter 2024 Quiz 1

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 1-4 of the Winter 2024 offering of DSC 10.

## Problem 1

Select all the true statements below.

• Mixing ints and floats in an arithmetic expression will always result in a float.

• Dividing two ints will sometimes result in an int.

• Any float can be converted to a string using the function str().

• Any string can be converted to a float using the function float().

Answer: Option 1 and Option 3

##### Difficulty: ⭐️⭐️

The average score on this problem was 87%.

## Problem 2

Consider the assignment statement below.

pear = [6, 10.1, "pear", 13]

What does the expression np.array(pear) evaluate to?

• array([6, 10.1, "pear", 13])

• array([6, 10.1, pear, 13])

• array(["6", "10.1", "pear", "13"])

• array(["pear"])

• array([pear])

• This expression errors

Answer: array(["6", "10.1", "pear", "13"])

##### Difficulty: ⭐️⭐️⭐️

The average score on this problem was 50%.

## Problem 3

Suppose x and y are both ints that have been previously defined, with x < y. Now, define:

peach = np.arange(x, y, 2)

Say that the spread of peach is the difference between the largest and smallest values in peach. The spread should be a non-negative integer.

### Problem 3.1

Using array methods, write an expression that evaluates to the spread of peach.

Answer: peach.max() - peach.min()

##### Difficulty: ⭐️⭐️⭐️

The average score on this problem was 62%.

### Problem 3.2

Without using any methods or functions, write an expression that evaluates to the spread of peach.
Hint: Use [ ].

Answer: peach[len(peach) - 1] - peach[0] or peach[-1] - peach[0]

##### Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 36%.

### Problem 3.3

Choose the correct way to fill in the blank in this sentence:

The spread of peach is ______ the value of y - x.

• always less than

• sometimes less than and sometimes equal to

• always greater than

• sometimes greater than and sometimes equal to

• always equal to

##### Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 48%.

## Problem 4

Suppose fruits is a DataFrame of the fruits Ashley bought at the grocery store, where:

• The "fruit" column contains the name of the fruit, as a string. All values in this column are distinct.

• The "price" column contains the amount in dollars spent on the fruit, as a float.

• The "pounds" column contains the number of pounds purchased, as an int.

### Problem 4.1

Fill in the blanks below to add a new column to fruits called "price_per_ounce" that contains the price per ounce of each of the fruits in fruits. There are 16 ounces in a pound.

    fruits = fruits.__(x)__(price_per_ounce = __(y)__ / __(z)__)

Answer (x): assign

##### Difficulty: ⭐️⭐️⭐️

The average score on this problem was 71%.

Answer (y): fruits.get("price")

##### Difficulty: ⭐️⭐️⭐️

The average score on this problem was 67%.

Answer (z): (fruits.get("pounds") * 16)

##### Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 43%.

### Problem 4.2

Write a line of code that evaluates to the amount of money, in dollars, that Ashley spent on fruit at the grocery store.

Answer: fruits.get("price").sum() or sum(fruits.get("price"))

##### Difficulty: ⭐️⭐️⭐️

The average score on this problem was 62%.

### Problem 4.3

Fill in the blanks so that the expression below evaluates to the name of the fruit with the highest price per ounce.

    (fruits.sort_values(by = "price_per_ounce", ascending = __(x)__)
.get(__(y)__).iloc[0])

Answer (x): False

##### Difficulty: ⭐️⭐️

The average score on this problem was 87%.

Answer (y): "fruit"

##### Difficulty: ⭐️⭐️⭐️

The average score on this problem was 65%.

### Problem 4.4

Assuming that "mango" is one of the fruits Ashley bought, fill in the blanks so that the expression below evaluates to the price per ounce of "mango".

    fruits.__(x)__("fruit").get("price_per_ounce").__(y)__["mango"]

Answer (x): set_index

##### Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 41%.

Answer (y): loc

##### Difficulty: ⭐️⭐️

The average score on this problem was 83%.