{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Assignment: Triangles\n",
"[Triangles](https://en.wikipedia.org/wiki/Triangle#Types_of_triangle) can be classified based on their angels.\n",
"\n",
"- A right triangle has one angle of 90°\n",
"- A obtuse triangle has one angle of more than 90°\n",
"- A triangle is acute if all three angels are less than 90°\n",
"\n",
"Write a program that asks the user for the values of three angles in degrees. First check if the entered values are\n",
"valid. The values are only valid if they are >0 and if their sum is 180°.\n",
"If the entered values are valid, classify the triangle as right, acute or obtuse.\n",
"\n",
"Below are two example executions of the program with invalid values:\n",
"\n",
" Please enter the first angle: 60\n",
" Please enter the second angle: 60\n",
" Please enter the third angle: 100\n",
" The entered values are not valid.\n",
"\n",
" Please enter the first angle: 200\n",
" Please enter the second angle: -10\n",
" Please enter the third angle: -10\n",
" Angles smaller than 0 are not valid.\n",
"\n",
"\n",
"Here is another example execution of the program:\n",
"\n",
" Please enter the first angle: 60\n",
" Please enter the second angle: 30\n",
" Please enter the third angle: 90\n",
" The triangle is a right triangle.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"angle_1 = int(input(\"Please enter the first angle: \"))\n",
"angle_2 = int(input(\"Please enter the second angle: \"))\n",
"angle_3 = int(input(\"Please enter the third angle: \"))\n",
"\n",
"if angle_1 <= 0 or angle_2 <= 0 or angle_3 <= 0:\n",
" print(\"Angles smaller than 0 are not valid.\")\n",
"elif angle_1 + angle_2 + angle_3 == 180:\n",
" if angle_1 == 90 or angle_2 == 90 or angle_3 == 90:\n",
" print(\"The triangle is a right triangle.\")\n",
" elif angle_1 > 90 or angle_2 > 90 or angle_3 > 90:\n",
" print(\"The triangle is an obtuse triangle.\")\n",
" else:\n",
" print(\"The triangle is an acute triangle.\")\n",
"else:\n",
" print(\"The entered values are not valid.\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}