Write a script file prompts a user for the three sides of a triangle (a, b, and
ID: 3935355 • Letter: W
Question
Write a script file prompts a user for the three sides of a triangle (a, b, and c) and uses the law of cosines to find the angles (A, B, and C). cos(C) = a^2 + b^2 - c^2/2ab cos (A) = b^2 + c^2 - a^2/2bc cos(B) = c^2 + a^2 - b^2/2ca Use print statements to print the sides a, b, and c and the angles in degrees A, B, and C. Write a python script that finds the roots of a quadratic equation. Make sure that the data type of the roots are floating point. Use a print statement to display the equation and the roots.Explanation / Answer
1.
import math
#inputing values
a = input("Enter side a: ")
b = input("Enter side b: ")
c = input("Enter side c: ")
#calculating angles using math.acos and converting them to degrees using math.degrees
C = math.degrees(math.acos((a**2.0+b**2.0-c**2.0)/(2.0*a*b)))
A = math.degrees(math.acos((b**2.0+c**2.0-a**2.0)/(2.0*b*c)))
B = math.degrees(math.acos((c**2.0+a**2.0-b**2.0)/(2.0*c*a)))
#outputing values
print "A = ", A, "B = ", B, "C = ", C
2.
import math
#inputing values for a, b and c
print "Assume that the quadratic equation is of the form: ax^2 + bx + c."
print "The input the values of a, b and c."
a = input("a: ")
b = input("b: ")
c = input("c: ")
#checking if discriminant < 0,
if b**2-4.0*a*c<0:
print "This equation doesn't have real roots."
else:
#calculating values of roots using the quadratic formula
root1 = (-b+math.sqrt(b**2-4.0*a*c))/(2.0*a)
root2 = (-b-math.sqrt(b**2-4.0*a*c))/(2.0*a)
#outputing the roots
print "The roots are,", root1, "and", root2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.