Question: in python Problem 6 (Distance Calculator) Write a program that repeatedly reads x and y coordinates representing the location of cities. Each time a new

in python

in python Problem 6 (Distance Calculator) Write a program that repeatedly reads

Problem 6 (Distance Calculator) Write a program that repeatedly reads x and y coordinates representing the location of cities. Each time a new city is entered, the program should calculate the Euclidean distance between the last city entered and the new city (i.e., how far it would be to travel between the two cities). The program should track the total distance and display it once the user enters "q" for either the x or y coordinate. Your program can assume that the user will always enter integer values. To calculate the square root of a value, you can import the math library (import math) and use the square root function (math.sqrt(some_number)). Note, if city #1 is at location (x1,y1) and city #2 is at location (x2,y2), the Euclidean distance between them can be calculated as: dist = (x1 - x2)2 + (y1 - y2)2 Hints: To calculate the increase in distance, you must have access to the x/y coordinates of both the city that was just entered by the user (call it new_city) and the previously entered city (call it old_city). When the user enters the x/y coordinates of the first city, the distance is just 0, so you do not need to calculate anything. You can, however, immediately initiallize 'old city' variables to store the xly coordinate of the first city. When another city is entered and stored in the 'new city' variables, you can calculate the distance and then update the values of the 'old city' variables

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 Databases Questions!