Question

This question is from the textbook "Python for ArcGIS" by Laura Tateosian: Write a script "triangles.py"...

This question is from the textbook "Python for ArcGIS" by Laura Tateosian:

Write a script "triangles.py" that takes three arguments, the lengths of three sides of a triangle. Then define the following three functions:

1. perimeter takes three side lengths as arguments and returns the perimeter length.

2. triangleType takes three side lengths as arguments, determines if it is an equilateral triangle, an isosceles triangle, or neither. The result is returned.

3. area takes three side lengths as arguments and returns the area. Compute this as the square root of (p*(p-a)*(p-b)*(p-c)), where p is half the perimeter and a, b, and c are the side lengths. Use a math module function to compute the square root.

Call the functions and print the results as shown below:

Example input: 1 1 1

Example output:

>>> Triangle sides: 1.0, 1.0, 1.0

Perimeter = 3.0

Type = Equilateral

Area = 0.4330127

0 0
Add a comment Improve this question Transcribed image text
Answer #1
If you copy the code as it is do check that the indentation is proper import math #to use a math module function to compute the square root 
class triangle: #creating a class a = float(input()) #input for first side b = float(input()) #input for second side c = float(input()) #input for third side print('triangle sides = ',a,',',b,',',c) #to print the given sides   def perimeter(a,b,c): #creating perimeter function p = a+b+c #to calculate the perimeter print('perimeter = ',p) #to print the perimeter def area(a,b,c): #creating area function p = (a + b + c) / 2 #calculates the half of the perimeter area = (p * (p - a) * (p - b) * (p - c)) #calculating the area area = math.sqrt(area) #calculating the area print('area = ',area) #to print the area def type(a,b,c): #creating typ function if a == b == c: #condition to check for equilateral triangle print("Type = Equilateral triangle") #to print it is equilateral triangle elif a == b or b == c or c == a: #condition to check for isosceles triangle print("Type = isosceles triangle") #to print it is isosceles triangle else: print("Type = Scalene triangle") #to print it is scalene triangle perimeter(a,b,c) #calling perimeter function type(a,b,c) #calling type function area(a,b,c) #calling area function 

Add a comment
Know the answer?
Add Answer to:
This question is from the textbook "Python for ArcGIS" by Laura Tateosian: Write a script "triangles.py"...
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
  • (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore,...

    (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have THREE private member variables → side1, side2 and side3. Use the double data type to represent the triangle sides. In addition, please provide public methods that perform the following FIVE tasks: ▪ An input method that obtains the appropriate values for the three sides from the user. While entering the values of the three sides, please remember the triangle property that...

  • MATLAB question Triangle Calculations (script with two anon functions) 0 solutions submitted (max: Unlimited) Consider a general triangle with side lengths a, b, and c and angles A, B, and C as shown...

    MATLAB question Triangle Calculations (script with two anon functions) 0 solutions submitted (max: Unlimited) Consider a general triangle with side lengths a, b, and c and angles A, B, and C as shown below Write a script that does the following Define the following two anonymous functions and assign to the indicated Function Handles: 1. The function ThirdSide should accept the lengths of sides a and b as well as angle C in that order and use the Law of...

  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

  • JAVA question Interface and Abstract Class (20 pts): There are three types of triangles in terms...

    JAVA question Interface and Abstract Class (20 pts): There are three types of triangles in terms of how many sides are equal: • Equilateral Isosceles Scalene There are three types of triangles in terms of the degrees of interior angles: • Right · Acute . Obtuse Right Isosceles triangle is a right triangle, as well as an isosceles triangle. Triangle 590° Right triangle Isosceles triangle Right isosceles triangle Create a public interface Triangle, add the following method signatures: • double...

  • ***IN PYTHON: Scalene triangle: All sides have different lengths Isosceles triangle: Two sides have the same...

    ***IN PYTHON: Scalene triangle: All sides have different lengths Isosceles triangle: Two sides have the same length Equilateral triangle: All sides are equal Write a program to ask for the length of 3 sides a, b and c. Ask for three sides at a time Determine the type of triangle given three sides Handle all kinds of errors - 1. not integers, int() conversion fails 2. not enough args, 3. too many arguments HINT: use the len() function to check...

  • Modify the Triangle class (from previous code, will post under this) to throw an exception in...

    Modify the Triangle class (from previous code, will post under this) to throw an exception in the constructor and set routines if the triangle is not valid (i.e., does not satisfy the triangle inequality). Modify the main routine to prompt the user for the sides of the triangle and to catch the exception and re-prompt the user for valid triangle sides. In addition, for any valid triangle supply a method to compute and display the area of the triangle using...

  • Write a MATLAB script that reads in three floating point values from the user (a, b...

    Write a MATLAB script that reads in three floating point values from the user (a, b and c), which represent the lengths of three sides of a triangle. Then compute the area of the triangle according to the equation: Area s(s-a)(s- b)(s -e) where s is half of the sum of the three sides, or the average of a, b, & c Hint: look up MATLAB function that prompts read-in values from user

  • help im alittle lost my teacher posted all this its suppose to be in C++ language....

    help im alittle lost my teacher posted all this its suppose to be in C++ language. can yoh leave comments ans type the code thank you Write a C++ program that accepts the lengths of three sides (a,b,c) of a triangle as input from the user Validate the user input, so that sides a, b, c can only be POSITIVE. The program output should indicate whether or not the triangle is an Equilateral Triangle, a Right Triangle, Isosceles which is...

  • C++ question-classes ? Implement a Triangle class in C++. The triangle is defined by its three...

    C++ question-classes ? Implement a Triangle class in C++. The triangle is defined by its three side lengths - a, b, and c. The class includes appropriate class constructors and public and private methods that perform the following operations: is_triangle - checks whether the given side lengths form a proper triangle; area - returns the area of the triangle; perimeter - returns the perimeter of the triangle; angle_a, angle_b, angle_c - return the vertex angles (in degrees) opposite to side...

  • Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 :...

    Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 : # Enter three points for a triangle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle: ")) # Compute the length of the three sides side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5 side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...

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