This is CsCircles, section 11C:geometry, , Excercise: The triangles are right. T
ID: 3779324 • Letter: T
Question
This is CsCircles, section 11C:geometry, , Excercise: The triangles are right. This is CsCircles, section 11C:geometry, , Excercise: The triangles are right.
Python language.
Cannot use sqrt for this excercise Perimeter Recall that the perimeter of a triangle is the sum of the sides. So in the diagram above, the perimeter has length a+b+c. Your program should assume that a correct version of hypotenuse has already been defined (you don't need to copy it from the first box to the second. Coding Exercise: TheTriangles are Right using hypotenuseca, b), define a function b) whichreturns the ength of the perimeter in a right triangle whose non-hypotenuse sides have lengths a and b. 1 def rightTrianglePrimeter a,b): 3 return p Run program Enter test statements Open in console Visualize More actions... Did not pass tests. Please check details below and try again. You cannot use sort in this exercise. Distance in 2 Dimensions
Explanation / Answer
#method hypotenuse which is finding hypotenuse without using sqrt
def hypotenuse(a, b):
return a ** 2.0 + b ** 2.0
#method perimeter returning hypotenuse+sidea+sideb
def rightTrianglePerimeter(a,b):
return hypotenuse(a, b) ** 0.5+a+b
#prompting user to enter sides other than hypotenuse
print "Enter the non-hypotenuse sides of the right triangle : "
#taking input for the side a
a = float(raw_input())
print "Length of Side A is", a
#taking input for the side b
b = float(raw_input())
print "Length of Side B is", b
#printing perimeter
print "The perimeter of the triangle is", rightTrianglePerimeter(a,b)
#OUTPUT: Enter the non-hypotenuse sides of the right triangle :
3
Length of Side A is 3.0
4
Length of Side B is 4.0
The perimeter of the triangle is 12.0
#OUTPUT
#Note:this code has been tested on python interpreter,please ask in case of any doubt,Thanks,God bless you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.