Introduction to Programming using Python 1st Edition

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

Chapter 4 - Selections - Programming Exercises - Page 128: 4.29

Answer

code

Work Step by Step

# 4.29 (Geometry: two circles) Write a program that prompts the user to enter the center # coordinates and radii of two circles and determines whether the second circle is # inside the first or overlaps with the first, as shown in Figure 4.11. (Hint: circle2 is # inside circle1 if the distance between the two centers <= | r1 - r2| and circle2 # overlaps circle1 if the distance between the two centers <= r1 + r2. Test your # program to cover all cases.) import math x1, y1, r1 = eval(input("Enter circle1's center x-, y-coordinates, and radius: ")) x2, y2, r2 = eval(input("Enter circle2's center x-, y-coordinates, and radius: ")) distance = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) if distance <= abs(r1 - r2): print("circle2 is inside circle1") elif distance <= r1 + r2: print("circle2 overlaps circle1") else: print("circle2 does not overlap circle1")
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.