Question

Write a program to compute the area of a triangle using side-angle-side method and reports the...

Write a program to compute the area of a triangle using side-angle-side method and reports the area of that triangle (rounded to 2 decimal places).

Side-angle-side formula: ???? = 1/ 2 ?? sin(?), where a and b are two sides of the triangle, and C is the included angle.

Your program must meet the following criteria to receive full marks:

• Randomly generate two values between 5 and 10 (inclusive) for two sides a and b of the triangle, respectively. You must use random module for this (see https://docs.python.org/3/library/random.html?highlight=random#module-random).

• Ask the user for the angle C in degrees (assume user always gives correct input for this one, i.e., a number between 0 and 180, inclusive).

• Python functions require angles in radians. So first convert the degrees value C to radians. You must use Python math module for this (see https://docs.python.org/3/library/math.html).

• Compute the area of the triangle and print the results as follows. You need to use Python math module here (https://docs.python.org/3/library/math.html#trigonometric-functions).

Sample output:

Enter a value for the angle (between 0 to 180): 45

The area of the triangle with a = 7, b = 6 and c = 45 degrees is 14.85

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# do comment if any problem arises

# Code


import random

import math

# generate random values for a and b

a=random.randint(5,10)

b=random.randint(5,10)

# read angle from user

c_degrees=int(input("Enter a value for the angle(between 0 to 180): "))

# convert to radians

c_radian=math.radians(c_degrees)

# calculate area

area=1/2*a*b*math.sin(c_radian)

# round to 2 decimal places

area=round(area,2)

print(f'The area of the triangle with a = {a},b = {b} and c = {c_degrees} degrees is {area}')


Screenshot:

Output:

Add a comment
Know the answer?
Add Answer to:
Write a program to compute the area of a triangle using side-angle-side method and reports the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT