Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NOTE: MODIFY THIS TO PYTHON CODE TO PRODUCE A BAD REFERENCE FOR THE MAP REFERENCE : D2 F23 Ja E23 Z2 For badly formatted map

image text in transcribed

image text in transcribed

NOTE: MODIFY THIS TO PYTHON CODE TO PRODUCE A BAD REFERENCE FOR THE MAP REFERENCE : D2 F23 Ja E23 Z2 For badly formatted map references, your program should exit, reporting the first bad map reference. HINT: You need to split the input line into separate references; each reference starts with one character which must be an upper case letter, and the rest must be only digits; and Pythagoras will help. The function exit() can abort the program if you detect an error in the input. # program that returns total distance def distance(reference): # split reference in different points points = reference.split() # initialize dist = 0 dist = 0 # traverse from Point-2 index to last-point index for i in range(1, len(points)): # x1 = x value of point (i-1) x1 = points[i - 1][0] # y1 = y value of point (i-1) y1 = int(points[i - 1][1:]) # x2 = x value of point i x2 = points[i][0] # y2 = y value of point i y2 = int(points[i][1:]) # if point (i-1) is wrong representation if (x1  'Z') or (y1  26): print('Bad reference: ' + points[i - 1]) exit() # if point i is wrong representation if (x2  'Z') or (y2  26): print('Bad reference: ' + points[i]) exit() # calculate change in x value from Point (i-1) to Point (i) xchange = (ord(x1) - ord(x2)) * 0.5 # calculate change in y value from Point (i-1) to Point (i) ychange = (y1 - y2) * 0.5 # using Pythagorous theorem dist += (xchange ** 2 + ychange ** 2) ** 0.5 # return final distance return dist # asking reference from user reference = input("Enter trip map references: ") # print Total Distance print('Total distance = ' + "{:.1f}".format(distance(reference)) + ' km') 
Problem: A road map defines locations as map references like B3, where B is the x-coordinate value and 3 is the y-coordinate. A B C D E F . Y Z 1 E2 2 3 B3 4 5 01 6 : 25 Y25 26 The grid lines are 0.5 km apart. Write a program that allows the user to enter a trip as a sequence of any number of map references on one line, and reports the total length of the trip, assuming they can travel in straight lines. For example: Enter trip map references: C2 B5 Y25 Total distance = 16.8 km Enter trip map references: D2 F23 Ja E23 Z2 Bad reference

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

How does an abstract word differ from a concrete word? [LO-4]

Answered: 1 week ago