Question
Using Python 3 Can a triangle be formed? Identify if a triangle can be formed and the type of triangle. Add iteration to enable the
Using Python 3
Can a triangle be formed?
Identify if a triangle can be formed and the type of triangle.
Add iteration to enable the user to repeat steps or automate steps by randomly generating three sides of a triangle. Use at least one function to make your code modular.
If you are given three sticks, you may or may not be able to arrange them in a triangle. For any three lengths, there is a simple test to see if it is possible to form a triangle:
If any of the three lengths is greater than the sum of the other two, then you cannot form a triangle. Otherwise, you can. If the triangle has side lengths a, b, and c, then all of the following must be true:
a+b>c
a+c>b
b+c>a
Ask the user to input the lengths of three sides of a triangle. Let the user know if a triangle can be formed with the given lengths.
If a triangle can be formed let the user know if it is an equilateral (all sides are equal), isosceles (any two sides are equal) or scalene (all sides are of different lengths) triangle.
After this ask the user if he/she wants to repeat or automate the above steps or if the user wants to quit. If the user selects repeat, then enable the user to repeat all of the above steps. If the user selects automate, then randomly generate three lengths in the range 1 through 5 where end points are inclusive. Then let the user know if a triangle can be formed and what type will be formed or that a triangle cannot be formed. If the user selects quit, bid bye and exit the program.
Add function(s) to avoid duplication of code. For example you can add functions for canATriangleBeFormed(side1, side2, side3) that returns true or false and/or typeOfTriangle(side1, side2, side3) that outputs the type of triangle
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started