SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:19 | ISBN:978013274719 | Edition: 6

Question

(Compute the perimeter of a triangle) Write a program that reads three edges for a triangle and computes the perimeter if the input is valid. Otherwise, display that the input is invalid. The input is valid if the sum of every pair of two edges is greater than the remaining edge. Here is a sample run:

 

Enter three edges: 1, 1, 1
The perimeter is 3

 

Enter three edges: 1, 3, 1
The input is invalid

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

#4.19.Perimeter of a triangle.
#Prompt the user to enter the edges of a triangle
a, b, c = eval(input("Enter the three egdes of a triangle:"))
perimeter = a + b + c

if a + b > c:
    print("The perimeter is ",perimeter)
elif a + c > b:
     print("The perimeter is ",perimeter)
elif b + c > a:
     print("The perimeter is ",perimeter)
else:
    print("Your input is invalid.")
    
 

1 0

Discussions

Post the discussion to improve the above solution.