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

True or False: `int(3.4)`

and `round(3.4)`

evaluate to the same value.

True

False

**Answer**: `True`

The average score on this problem was 89%.

True or False: For any float `x`

, `int(x)`

and
`round(x)`

evaluate to the same value.

True

False

**Answer**: `False`

The average score on this problem was 95%.

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
```

What is the value of `poppy`

after this code is
executed?

**Answer**: `21.0`

The average score on this problem was 54%.

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.

**Answer**: Option D

The average score on this problem was 68%.

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.

**Answer**: Option B

The average score on this problem was 79%.

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`

The average score on this problem was 84%.

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`

.

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")`

The average score on this problem was 79%.

**Important:** The following questions will use
`flowers`

instead of `flower_data`

.

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)`

**Answer**: Option B

The average score on this problem was 83%.

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`

The average score on this problem was 83%.

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]`

The average score on this problem was 46%.