Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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' variablesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started