# Spring 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 Spring 2024 offering of DSC 10.

## Problem 1

### Problem 1.1

True or False: int(3.4) and round(3.4) evaluate to the same value.

• True

• False

Answer: True

##### Difficulty: ⭐️⭐️

The average score on this problem was 89%.

### Problem 1.2

True or False: For any float x, int(x) and round(x) evaluate to the same value.

• True

• False

Answer: False

##### Difficulty: ⭐️

The average score on this problem was 95%.

## Problem 2

Consider the following code.

iris = 3 / 1
poppy = 8 - 6
daisy = np.array([8, 1, 5])
lily = np.array([4, 2])
poppy = iris ** iris - iris * poppy

### Problem 2.1

What is the value of poppy after this code is executed?

Answer: 21.0

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

The average score on this problem was 54%.

### Problem 2.2

What is the result of the expression daisy + lily?

• array([8, 1, 5, 4, 2])

• array([12, 3, 5])

• array([12, 3])

• This expression errors.

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

The average score on this problem was 68%.

### Problem 2.3

What is the result of the expression daisy + lily[0]?

• array([8, 1, 5, 4])

• array([12, 5, 9])

• array([10, 3, 7])

• This expression errors.

##### Difficulty: ⭐️⭐️

The average score on this problem was 79%.

## Problem 3

You are tracking the growth of a flower stem over a seven-day period. The flower stem starts out at 24.5 cm and ends up at 29.7 cm.

Write one line of code that calculates the average daily growth, in centimeters, and assigns the result to the variable avg_growth. Do not round your answer.

Answer: avg_growth = (29.7 - 24.5) / 7

##### Difficulty: ⭐️⭐️

The average score on this problem was 84%.

## Problem 4

Suppose flower_data is a DataFrame with information on different species of flowers, where:

• The "species" column contains the name of the species of flower, as a string. Each value in this column is unique.

• The "petals" column contains the average number of petals of flowers of this species, as an int.

• The "length" column contains the average stem length of flowers of this species in inches, as a float.

### Problem 4.1

One of these three columns is a good choice to use as the index of this DataFrame. Write a line of code that sets this column as the index of flower_data, and assigns the resulting DataFrame to the variable flowers.

Answer: flowers = flower_data.set_index("species")

##### Difficulty: ⭐️⭐️

The average score on this problem was 79%.

Important: The following questions will use flowers instead of flower_data.

### Problem 4.2

Which of the following expressions evaluates to a DataFrame that is sorted by "petals" in descending order?

• flowers.sort_values(by = "petals", ascending = True)

• flowers.sort_values(by = "petals", ascending = False)

• flowers.get("petals").sort_values(ascending = True)

• flowers.get("petals").sort_values(ascending = False)

##### Difficulty: ⭐️⭐️

The average score on this problem was 83%.

### Problem 4.3

Suppose that the 4th row of flowers corresponds to a rare species of flower named "fire lily". Fill in the blanks below so that both of these expressions evaluate to the stem length in inches of "fire lily".

i. flowers.get("length").loc[__(x)__]
ii. flowers.get("length").iloc[__(y)__]

Answer: (x): "fire lily", (y): 3

##### Difficulty: ⭐️⭐️

The average score on this problem was 83%.

### Problem 4.4

Suppose that the 3rd row of flowers corresponds to the species "stinking corpse lily". Using the flowers DataFrame and the string method .split(), write an expression that evaluates to "corpse".

Answer: flowers.index[2].split(" ")[1]

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

The average score on this problem was 46%.