-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle_error.py
More file actions
43 lines (37 loc) · 1.56 KB
/
Copy pathtriangle_error.py
File metadata and controls
43 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def classify_triangle(angle1, angle2, angle3):
# Classify the triangle without checking if the angles form a valid triangle
if angle1 == angle2 == angle3:
triangle_type = "Equilateral"
elif angle1 == angle2 or angle2 == angle3 or angle1 == angle3:
triangle_type = "Isosceles"
else:
triangle_type = "Scalene"
# Determine the subtype of the triangle
if angle1 < 90 and angle2 < 90 and angle3 < 90:
subtype = "Acute"
elif angle1 == 90 or angle2 == 90 or angle3 == 90:
subtype = "Right-angled"
else:
subtype = "Obtuse"
return f"{triangle_type} and {subtype}"
def get_valid_angle(prompt):
while True:
try:
angle = int(input(prompt))
# Removed the check for positive integers
return angle
except ValueError as e:
print(f"Invalid input: {e}. Please enter a positive integer.")
while True:
# Take inputs from the user
print("Please enter the angles of the triangle:")
angle1 = get_valid_angle("Enter the first angle: ")
angle2 = get_valid_angle("Enter the second angel: ") # Typo in the prompt
angle3 = get_valid_angle("Enter the third angle: ")
# Classify and print the type of triangle
triangle_description = classify_triangle(angle1, angle2, angle3)
print(f"The traingle is {triangle_description}.")
# Ask the user if they want to classify another triangle or exit
choice = input("Press 'e' to exit or any other key to classify another triangle: ").strip().lower()
if choice == 'e':
break