Question

In: Computer Science

(PYTHON) Write aprogram that prompts user to enter three sides of a triangle....

(PYTHON) Write a program that prompts user to enter three sides of a triangle. The program should determine if the three sides can form a triangle. If the three sides can form a triangle, then determine the type of the triangle.
There are three types of triangles:

  • Equilateral triangle (all 3 sides are equal)
  • Isosceles triangle (two sides are equal, the third side is of a different length)
  • Scalene triangle (all 3 sides are of different lengths)

 

The program should have a function called triangle_type() that takes 3 parameters, the lengths of each side. The triangle_type() function should return Equilateral, Isosceles, or Scalene according to the descriptions above. Do not use global variables. Function parameters must be used.

Solutions

Expert Solution

Description:

3 sides can form a triangle only if sum of any two sides exceeds the other side.

Code:

def triangle_type(a, b, c):#determines triangle type
if(a==b):#1st and 2nd sides are equal
if(b==c):#2nd and 3rd sides are equal
return "Equilateral"
else:
return "Isosceles"
elif(b==c):#3rd and 2nd sides are equal
return "Isosceles"
elif(a==c):#1st and 3rd sides are equal
return "Isosceles"
return "Scalene"#if no side is equal
x = int(input("Enter side1: "))
y = int(input("Enter side2: "))
z = int(input("Enter side3: "))
if((x + y > z) and ( x + z > y) and (y + z > x)):#sum of 2 sides should be greater than 3rd side
print("Triangle is " + triangle_type(x, y, z))
else:
print("Given sides cannot form a triangle")

Image of Code:

Output:


Related Solutions

Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
Write a Python program using functions and mainline logic which prompts the user to enter a...
Write a Python program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum, the numbers should...
Write a PYTHON program that prompts the user to enter the account’s present value, yearly interest...
Write a PYTHON program that prompts the user to enter the account’s present value, yearly interest rate, and the number of years that the money will be left in the account. The program should pass these values to a function that returns the future value of the account, after the specified number of months. The program should display the accounts’ future value
In PYTHON OF JUPIDER NOTEBOOK Write a program that prompts the user to enter his/her nationality...
In PYTHON OF JUPIDER NOTEBOOK Write a program that prompts the user to enter his/her nationality (French/french, Italian/italian, or Spanish/spanish). Then ask his/her name using a prompt message in his/her own language (use Google Translate if you need). After getting the name, again greet him/her using a greeting message in his/her own language. If the user is not from any of the above nationalities just use English to prompt for name and to greet the user. Example 1: Nationality? french...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
Write a C# program that prompts the user to enter in three values. The first indicates...
Write a C# program that prompts the user to enter in three values. The first indicates a starting (whole number positive) value, the second an ending value and the third an increase value. output a table of squares and square roots, every increase value from the start to the end value. For instance if the values were: start 3, end 20, and increase 4. the table would consist of 3,7,11,15,19 and their squares and square roots. Please include all code...
python.Write a python program that prompts the user to enter the year and first day of...
python.Write a python program that prompts the user to enter the year and first day of the year, and displays the first day of each month in the year. For example, if the user entered the year 2020 and 3 for Wednesday, January 1, 2020, your program should display the following output: January 1, 2020 is Wednesday February 1, 2020 is Saturday …… December 1, 2020 is Tuesday
Part 1 Write a program that prompts the user to enter three sets of five double...
Part 1 Write a program that prompts the user to enter three sets of five double numbers each. These numbers represent the five grades that each of three students has received. After prompting for the grades, the program: stores the data in a previously defined 3◊5 double array computes the average of each set of 5 grades after acquiring the grades for that one student determines the maximum and minimum values of each set of 5 grades acquiring the grades...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and print the average of the numbers. 2. Write a Java program that uses a for loop to print the odd numbers from 1 to 20. Print one number per line in the command line window. 3. Write a program which asks the user to input the size of potatoe fries she would like to purchase, and based on the size, it will tell her...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT