LearnFrenzy
Sign in Take a free test

Modules and Packages · Modules and Packages Coding Problems · Question 7

Geometry calculator with the math module in Python Solution, output & explanation

  • Program
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

Use math to compute the hypotenuse of a right triangle, the area of a circle, the angle of a ramp in degrees, and the distance between two points.

Solution
main.py Run
import math

print("Hypotenuse of 5, 12:", math.hypot(5, 12))
print("Circle area r=3:", round(math.pi * 3 ** 2, 2))
print("Ramp angle (rise 1, run 12):", round(math.degrees(math.atan2(1, 12)), 2), "degrees")
print("Distance (1,2)-(4,6):", math.dist((1, 2), (4, 6)))
print("sin 30°:", round(math.sin(math.radians(30)), 2))

Output Verified by running it on Python 3

Hypotenuse of 5, 12: 13.0
Circle area r=3: 28.27
Ramp angle (rise 1, run 12): 4.76 degrees
Distance (1,2)-(4,6): 5.0
sin 30°: 0.5

Trigonometric functions use radians, so convert with math.radians and math.degrees.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links