Distance in the coordinate system (150 p) This exercise is about the following topics ● Using multidimensional lists ● Using strings ● Handling exceptions Initial preparations Create a new project in...

1 answer below »
Python code with that file


Distance in the coordinate system (150 p) This exercise is about the following topics ● Using multidimensional lists  ● Using strings  ● Handling exceptions  Initial preparations Create a new project in Eclipse or PyCharm named "assignment6_2" and create a new  module in this project named for example "distance".  Background Many map applications allow the user to calculate the distance when the route goes  through specific points. In this exercise we calculate the distance in the traditional XY  coordinate system that goes through the points the user gave as an input.  Description of the exercise Write a program that asks the user to input the coordinates for points until the user  inputs an empty string. The coordinates can be any decimal numbers and the user  inputs them in the format 'x,y', where x is the x coordinate of the point and y is the y  coordinate of the same point. The program calculates and prints the total distance  travelled in the coordinate system going through all the input points. In addition, the  program calculates the distance between the starting point and the end point going  through the most direct route.  Structure of the program Write the following functions to the program:  ● calculate_distance_between_points(point1, point2) ○ The function calculates the distance between two points.  ○ The function gets two lists as a parameter: the first list contains the x and  y coordinates of the start point and the other contains the x and y  coordinates of the end point.  ○ The functions returns the distance between the two points.  ● calculate_total_distance(point_list) ○ The function gets a two-dimensional list as a parameter. The  two-dimensional list contains the x and y coordinates for each point as a  list. The points are in the two-dimensional list in the same order the user  inputted them to the program. The list could be for example ​[[3.2, 1.4], [5.6, 7.7], [-1.2, 6.0]]​, so we would start from the point  3.2,1.4, go through the point 5.6,7.7 and end in the point -1.2,6.0.  ○ The function return the total distance between the starting point and the  end point going through all the points in the list.  Your program must include the functions described above. The names and the  parameters of the function must correspond to the the ones above. Otherwise you  cannot get full points from this exercise.  In addition, write the main program that asks the user to input the coordinates for  each point and prints the calculated distances.  Error handling The program should handle the following errors:  ● The user's input does not contain both x and y coordinates in the format 'x,y'.  ○ The program informs the user of this and continues asking for the  coordinates normally.  ● The user does not input any coordinates or inputs coordinates only for one  point.  ○ The program prints "Not enough data." and terminates.  You can assume that the user only inputs such input that the coordinates are in  decimal form.  Output of the program The program prints the distance rounded to two decimal places. Pay close attention  that the output of your program is approximately according to the example execution  below (letter case, line breaks, spaces, full stops, commas, exclamation points or  question marks are not checked even though they might be highlighted in the test  feedback.)  Submitting Run your program with multiple different inputs and check that the output is correct.  Submit the file ​distance.py​ to A+.  Examples of the execution of the program: [execution of the program begins] Enter the coordinates in the format 'x,y'. Stop with an empty line. 1.1,2.1 Enter the coordinates: 3.2,1.5 Enter the coordinates: 4.2,0.7 Enter the coordinates: The total distance going through all the points is 3.46 units long. The straight line from the starting point to the end is 3.40 units long. [execution of the program ends] Enter the coordinates in the format 'x,y'. Stop with an empty line. 2.1 Enter the coordinates in the format 'x,y'. Enter the coordinates: 2.1,8.3,5.6 Enter the coordinates in the format 'x,y'. Enter the coordinates: 2.1,3.0 Enter the coordinates: 3.0,2.1 Enter the coordinates: 2.1,3.0 Enter the coordinates: The total distance going through all the points is 2.55 units long. The straight line from the starting point to the end is 0.00 units long. [execution of the program ends] [execution of the program begins] Enter the coordinates in the format 'x,y'. Stop with an empty line. -0.8888,0.255 Enter the coordinates: 0.6898,-0.255 Enter the coordinates: -8.6347,2.8456 Enter the coordinates: -1.4222,-3.6401 Enter the coordinates: -1.0403,4.42 Enter the coordinates: 6.39,0.4888 Enter the coordinates: The total distance going through all the points is 37.66 units long. The straight line from the starting point to the end is 7.28 units long. [execution of the program ends] [execution of the program begins] Enter the coordinates in the format 'x,y'. Stop with an empty line. Not enough data. [execution of the program ends] [execution of the program begins] Enter the coordinates in the format 'x,y'. Stop with an empty line. 1.2,1.3 Enter the coordinates: Not enough data. [execution of the program ends]
Answered Same DayOct 25, 2021

Answer To: Distance in the coordinate system (150 p) This exercise is about the following topics ● Using...

Aditya answered on Oct 26 2021
147 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here