Python Conditional: Exercise - 36 with SolutionWrite a Python program to check a triangle is equilateral, isosceles or scalene. Show
Pictorial Presentation: Sample Solution: Python Code:
Sample Output: x: 6 y: 8 z: 12 Scalene triangle Flowchart : Visualize Python code execution:The following tool visualize what the computer is doing step-by-step as it executes the said program: Python Code Editor: Have another way to solve this solution? Contribute your code (and comments) through Disqus. Previous:
Write a Python program to check a string represent an integer or not? In this article, we will learn how to find the type of triangle with given sides in Python. Let a, b, c represent the sides of the triangle. Examples Input: a = 5, b = 4, c = 3 Output: Right-angled triangle Input: a = 3, b = 3, c = 3 Output: Acute-angled triangle In general, if c² = a² + b² then the triangle is a right-angled triangle. c² < a² + b² then the triangle is an acute-angle triangle. c² > a² + b² then the triangle is an obtuse-angle triangle. Type of triangle in Python1. Get the sides of the triangle from the user. 2. Calculate the square of each side of the triangle. 3. Check if sa == sc + sb or sb == sa+sc or sc == sa+sb then print Right-angled triangle. 4. If sa > sc + sb or sb > sa+sc or sc > sa+sb then print Obtuse-angled triangle. 5. Else, print Acute-angled triangle. def triangleType(a, b, c): sa = pow(a, 2) sb = pow(b, 2) sc = pow(c, 2) if (sa == sc + sb or sb == sa+sc or sc == sa+sb): print("Right-angled triangle") elif (sa > sc + sb or sb > sa+sc or sc > sa+sb): print("Obtuse-angled triangle") else: print("Acute-angled triangle") a = int(input("Enter side a: ")) b = int(input("Enter side b: ")) c = int(input("Enter side c: ")) triangleType(a, b, c) Output Enter side a: 10 Enter side b: 6 Enter side c: 8 Right-angled triangle Enter side a: 5 Enter side b: 7 Enter side c: 8 Acute-angled triangle Enter side a: 12 Enter side b: 7 Enter side c: 8 Obtuse-angled triangle Also, read
31. Python Program to read Three sides of a triangle and print the type of the triangle.How does this program work?
Here is the code //To read three sides of a Triangle and print the type of the triangle How do you identify a triangle type?Define acute, obtuse and right triangle.
In an acute triangle, all the angles of a triangle are less than 90 degrees. In an obtuse triangle, one of the angles of a triangle is greater than 90 degrees. In a right triangle, one angle measures 90 degrees and the other two angles are acute.
How do you know if a python is isosceles triangle?isosceles triangle code in python. print("Input lengths of the triangle sides: "). x = int(input("x: ")). y = int(input("y: ")). z = int(input("z: ")). if x == y == z:. print("Equilateral triangle"). elif x==y or y==z or z==x:. How do you use the triangle method in Python?The function Triangle() takes the given points as vertices of a triangle and computes the area of triangle with the help of area. Syntax: Triangle(x, y, z). area Parameters: where x, y, z are coordinates. Return: Area of triangle.
How do you code an equilateral triangle in Python?def triangle(n):. for i in range(1, n+1):. print(' ' * n, end=''). print('* '*(i)). n -= 1.. n = int(input()). triangle(n). |