Assignment 10 — multi-input problem solving
Due Tuesday, September 17
Problem manhattan_distance.py
- FYI: the built-in Python function abs() computes absolute values. It should prove helpful for this assignment.
- The program takes as its integer input, the street and avenue of one corner in Manhattan and the street and avenue of another corner in Manhattan. The program then computes an estimate of the distance between the two locations using the above formula. The only program output besides the prompts is the estimate.
- Note: the program is to make only two prompts for data, each with two inputs on a single line, as demonstrated in the sample runs below.
- New Yorkers approximate distance between two Manhattan locations using the number of streets and avenues separating the starting and ending locations.
- The approximation uses the following estimates.
- The distance of a Manhattan city block running from one street to the next street is on average 1/20th of a mile.
- The distance of a Manhattan city block running from one avenue to the next avenue is on average 3/20th of mile.
- Based on these block length estimates, the distance from the corner at street s1 and avenue a1 to the corner of street s2 and avenue a2 is
( 0.05 × | s1 – s2 | ) + ( 0.15 × | a1 – a2 | )
- If you do not remember | |’s from high school algebra, | s1 – s2 | is the absolute value of s1 – s2 and | a1 – a2 | is the absolute value of a1 – a2.
- It is important to calculate the absolute values of the street differences and avenue differences separately.
- Your only output should be the distance between the two locations and nothing else.
- Because both input prompts should cause the user to supply two values, string function
split()
should prove helpful. See string documentation for information onsplit()
or the post-classbreak_the_bank.py
artifact.
Two different sample runs
Starting corner (street and avenue): 59 6
Ending corner (street and avenue): 34 7
1.4
Starting corner (street and avenue): 47 2
Ending corner (street and avenue): 238 6
10.15
© 2019 Jim Cohoon | Resources from previous semesters are available. |