Question: Write a program that prompts the user for the number of street blocks they must travel and the number of avenue blocks they must travel,

Write a program that prompts the user for the number of street blocks they must travel and the number of avenue blocks they must travel, and then calculates how much shorter the crows flight would be.
Your program should treat the numbers of blocks as integers, and should report the difference between the taxicab distance and the crows distance in miles, to two decimal places of precision.
Note that the crow distance will always be less than or equal to the taxicab distance, and that your answer should never be negative. *
Use constants for street blocks per mile and avenue blocks per mile.
Your program must have two functions:
taxicab_distance(streets, avenues) which, given the number of street blocks and number of avenue blocks, returns the taxicab distance. Notice that the inputs here are numbers of blocks and the output is a distance, so youll need to perform a conversion within the function.
crow_distance(streets, avenues) which, given the number of street blocks and number of avenue blocks, returns the crow distance. Notice that the inputs here are numbers of blocks and the output is a distance, so youll need to perform a conversion and additional computation within the function.
Neither of these functions should prompt the user for input. Neither of these functions should print anything. Call these functions as needed in the body of your program.
Your program does not need to handle negative distances correctly. In fact, it shouldnt. So dont worry about negative values for street blocks and avenue blocks.
Examples (each a separate run of your program):
How many street blocks must you travel? 201
How many avenue blocks must you travel? 71
The crow's flight is 5.91 miles shorter.
How many street blocks must you travel? 9
How many avenue blocks must you travel? 21
The crow's flight is 0.42 miles shorter.
How many street blocks must you travel? 100
How many avenue blocks must you travel? 0
The crow's flight is 0.00 miles shorter.
Your output should match the above! Please test before submitting!
Hint: Remember Pythagoras and use math.sqrt(). You wont need anything else from the math module, just math.sqrt().
Tip
Autograder tip: Prompts and output should each be on a single line. Prompt for street blocks first, then avenue blocks. Display result to two decimal places, using an f-string with format specifier. The autograder will look for your answer on the line containing the string 'flight', so please follow the examples above as a guide.
Rubric
points objective
0.5- Docstring at top of file
2.0- taxicab_distance function
2.0- crow_distance function
1.0- Program runs and terminates normally
3.0- Correct calculations and output
8.5 TOTAL
* This is what is called the triangle inequality. Given lengths of two sides of a triangle,
x
x and
y
y, the length of the remaining side
z
z is subject to the following constraint
z
<=
x
+
y
z<=x+y
Note that
z
z only equals
x
+
y
x+y in the degenerate case where all three points of the triangle are collinear.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!