Introduction to Programming using Python 1st Edition

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

Chapter 3 - Mathematical Functions, Strings, and Objects - Programming Exercises - Page 89: 3.18

Answer

import math import turtle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points: ")) a = math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) b = math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)) c = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) A = math.degrees(math.acos((a * a - b * b - c * c) / (-2 * b * c))) B = math.degrees(math.acos((b * b - a * a - c * c) / (-2 * a * c))) C = math.degrees(math.acos((c * c - b * b - a * a) / (-2 * a * b))) A = format(A,"0.2f") B = format(B,"0.2f") C = format(C,"0.2f") turtle.penup() turtle.goto(x1, y1) turtle.pendown() turtle.write(str(A)) turtle.goto(x2, y2) turtle.write(str(B)) turtle.goto(x3, y3) turtle.write(str(C)) turtle.goto(x1, y1) turtle.done()

Work Step by Step

# (Turtle: triangle angles) Revise Listing 3.2, ComputeAngles.py, to write a program # that prompts the user to enter the three points p1, p2, and p3 for a triangle # and display its angles, as shown in Figure 3.7b. import math import turtle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points: ")) a = math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) b = math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)) c = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) A = math.degrees(math.acos((a * a - b * b - c * c) / (-2 * b * c))) B = math.degrees(math.acos((b * b - a * a - c * c) / (-2 * a * c))) C = math.degrees(math.acos((c * c - b * b - a * a) / (-2 * a * b))) A = format(A,"0.2f") B = format(B,"0.2f") C = format(C,"0.2f") turtle.penup() turtle.goto(x1, y1) turtle.pendown() turtle.write(str(A)) turtle.goto(x2, y2) turtle.write(str(B)) turtle.goto(x3, y3) turtle.write(str(C)) turtle.goto(x1, y1) turtle.done()
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.