← 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 Winter 2024 offering
of DSC 10.

Select all the true statements below.

Mixing

`int`

s and`float`

s in an arithmetic expression will always result in a`float`

.Dividing two

`int`

s 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

The average score on this problem was 87%.

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

The average score on this problem was 50%.

Suppose `x`

and `y`

are both `int`

s
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.

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

.

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

The average score on this problem was 62%.

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

The average score on this problem was 36%.

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

**Answer:** always less than

The average score on this problem was 48%.

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`

.

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.__(x)__(price_per_ounce = __(y)__ / __(z)__) fruits `

**Answer (x):** `assign`

The average score on this problem was 71%.

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

The average score on this problem was 67%.

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

The average score on this problem was 43%.

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

The average score on this problem was 62%.

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

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

**Answer (x):** `False`

The average score on this problem was 87%.

**Answer (y):** `"fruit"`

The average score on this problem was 65%.

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

.

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

**Answer (x):** `set_index`

The average score on this problem was 41%.

**Answer (y):** `loc`

The average score on this problem was 83%.