{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6838b2de",
   "metadata": {},
   "source": [
    "# Hello"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4200d243",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\"\"\"\n",
    "       Python programm to calculate the third side of a triangle by the Cosine Rule\n",
    "       and the three angle of the triangle by the Sin Rule.\n",
    "\"\"\"\n",
    "\n",
    "import math\n",
    "\n",
    "def main():\n",
    "    \n",
    "    #    Get the lengths of two sides and angle between them\n",
    "    a = float(input(\"First side of triangle : \"))\n",
    "    b = float(input(\"Second side of triangle : \"))\n",
    "    theta_c = float(input(\"Angle between them : \"))\n",
    "    \n",
    "    #      Convert theta_c to radians\n",
    "    theta_c = math.radians(theta_c)\n",
    "    \n",
    "    #       Calculate length of side c by the cosine rule\n",
    "    #       Note the order of operators and minimal use of brackets.\n",
    "    c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(theta_c))\n",
    "\n",
    "    print(\"Length of third side by cosine rule is : \" + str(c))\n",
    "    \n",
    "    #      Use sin rule to calcuate angle. \n",
    "    #     Note all angle converted back to degree to make them humanly readable.\n",
    "    ratio = c/math.sin(theta_c)\n",
    "    theta_a = math.degrees(math.asin(a/ratio))\n",
    "    theta_b = math.degrees(math.asin(b/ratio))\n",
    "    theta_c = math.degrees(theta_c)\n",
    "    \n",
    "    print(\"Angles are A: \" + str(theta_a) + \" B:\" + str(theta_b) + \" C: \" + str(theta_c))\n",
    "   \n",
    "#    Run the program\n",
    "main()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}