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:
taxicabdistancestreets 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.
crowdistancestreets 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?
How many avenue blocks must you travel?
The crow's flight is miles shorter.
How many street blocks must you travel?
How many avenue blocks must you travel?
The crow's flight is miles shorter.
How many street blocks must you travel?
How many avenue blocks must you travel?
The crow's flight is 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 fstring 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
Docstring at top of file
taxicabdistance function
crowdistance function
Program runs and terminates normally
Correct calculations and output
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
zxy
Note that
z
z only equals
x
y
xy 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
