Python programming - the description is in the picture. This involves functions
ID: 643146 • Letter: P
Question
Python programming - the description is in the picture. This involves functions but I am lost on where to start (The MyTriangle module) Create a module named MyTriangle that contains The following two functions: Write a test program that reads three sides for a triangle and computes the area if the Input is valid. Otherwise, it displays that the input is invalid. The formula for computing area of a triangle is given in Exercise 2.14. Here are some sample runs: Python programming - the description is in the picture. This involves functions but I am lost on where to startExplanation / Answer
import math
def isValid(side1, side2, side3):
if side1 > side2 and side1 > side3:
return side1 >= side2 + side3
elif side2 > side1 and side2 > side3:
return side2 >= side1 + side3
else:
return side3 >= side1 + side2
def area(side1, side2, side3):
p = (side1 + side2 + side3) / 2
return math.sqrt(p * (p - side1) * (p - side2) * (p - side3))
def main():
sides = input('Enter three sides in double: ')
s = sides.split(' ')
side1 = float(s[0])
side2 = float(s[1])
side3 = float(s[2])
if isValid(side1, side2, side3):
print('Input is invalid!')
else:
print('The area of the triangle is ' + str(area(side1, side2, side3)))
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.