Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 393: 11.34

Answer

code

Work Step by Step

# 11.34 (Geometry: rightmost lowest point) In computational geometry, often you need to # find the rightmost lowest point in a set of points. Write the following function that # returns the rightmost lowest point in a set of points: # # Return a list of two values for a point # def getRightmostLowestPoint(points): # Write a test program that prompts the user to enter the coordinates of six points # and displays the rightmost lowest point. def main(): line = input("Enter six points: ").split() p = [[eval(line[i]), eval(line[i + 1])] for i in range(0, 6, 2)] point = getRightmostLowestPoint(p) print("The rightmost lowest point is (" + str(point[0]) + ", " + str(point[1]) + ")") def getRightmostLowestPoint(p): rightMostIndex = 0 rightMostX = p[0][0] rightMostY = p[0][1] for i in range(1, len(p)): if rightMostY > p[i][1]: rightMostY = p[i][1] rightMostIndex = i elif rightMostY == p[i][1] and rightMostX < p[i][0]: rightMostX = p[i][0] rightMostIndex = i return [p[rightMostIndex][0], p[rightMostIndex][1]] main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.