##### ► Python program to calculate perimeter of a triangle

Steps followed:
1. take all three sides of triangle as input from user
2. validate user input by converting to float
3. calculate perimeter of triangle using formula side1 + side2 + side3
4. print perimeter of triangle

Program
``````#python program to calculate perimeter of a triangle

#take all three sides of triangle as input from user
side1=input("Enter first side of triangle: ")
side2=input("Enter second side of triangle: ")
side3=input("Enter third side of triangle: ")

try:
side1=float(side1)
side2=float(side2)
side3=float(side3)

#calculate perimeter of triangle
perimeter = side1 + side2 + side3

#print perimeter of triangle
print("---output---")
print("perimeter of triangle with sides %0.2f,%0.2f,%0.2f is %0.2f"%(side1,side2,side3,perimeter))

except:
print("---error---")

Output
``````Enter first side of triangle: 3
Enter second side of triangle: 4
Enter third side of triangle: 5
---output---
perimeter of triangle with sides 3.00,4.00,5.00 is 12.00

Enter first side of triangle: a
Enter second side of triangle: b
Enter third side of triangle: 12
---error---