Using the map below, she sees she'd have
to walk 3 avenues (long blocks) and 8 streets (short blocks).
In terms of the
given numbers, she computed 3 as the difference between 7 and 10, *in absolute
value*, and 8 similarly.
#
# Chunhua also knows that blocks in Manhattan are all about 80m by 274m (avenues
are farther apart than streets).
So in total, she'd have to walk $(80 \times |
42 - 34| + 274 \times |7 - 10|)$ meters to get to the park.
#
# <img src="map.jpg" alt="visual map about distance calculation"/>
#
# **Question 3.1.1.** <br /> Finish the line `num_avenues_away = ...` in the
next cell so that the cell calculates the distance Chunhua must walk and gives
it the name `manhattan_distance`.
Everything else has been filled in for you.
**Use the `abs` function.**

# In[31]:
# Here's the number of streets away:
num_streets_away = abs(42-34)
# Compute the number of avenues away in a similar way:
num_avenues_away = abs(7-10)
street_length_m = 80
avenue_length_m = 274
# Now we compute the total distance Chunhua must walk.
manhattan_distance = street_length_m*num_streets_away +
avenue_length_m*num_avenues_away
# We've included this line so that you see the distance
# you've computed when you run this cell.
You don't need
# to change it, but you can if you want.
manhattan_distance
# Be sure to run the next cell to test your code.
# In[32]:
check('tests/q311.py')
# ##### Multiple arguments
# Some functions take multiple arguments, separated by commas. For example, the
built-in `max` function returns the maximum argument passed to it.
# In[33]:
max(2, -3, 4, -5)
# ## 4. Understanding nested expressions
# Function calls and arithmetic expressions can themselves contain expressions.
You saw an example in the last question:
#
#
abs(42-34)
#
# has 2 number expressions in a subtraction expression in a function call
expression.
And you probably wrote something like `abs(7-10)` to compute
`num_avenues_away`.
#
# Nested expressions can turn into complicated-looking code. However, the way in
which complicated expressions break down is very regular.
#
# Suppose we are interested in heights that are very unusual.
We'll say that a
height is unusual to the extent that it's far away on the number line from the
average human height.
[An estimate]
(;) of the
average adult human height (averaging, we hope, over all humans on Earth today)
is 1.688 meters.
#
# So if Aditya is 1.21 meters tall, then his height is $|1.21 - 1.688|$, or
$.478$, meters away from the average.
Here's a picture of that:
#

#### You've reached the end of your free preview.

Want to read all 13 pages?

- Fall '17
- Human height