codescracker


python

Python Program to Calculate Perimeter of Triangle



« Previous Program Next Program »


Calculate Perimeter of Triangle in Python

To calculate perimeter of a triangle in python, you have to ask from user to enter length of first, second, and third side of the triangle to calculate perimeter of that triangle as shown in the program given below.

Python Programming Code to Calculate Perimeter of Triangle

Following python program ask from user to enter the length of all the three sides of triangle to find the perimeter of that triangle:

# Python Program - Calculate Perimeter of Triangle
		
while True:
	print("Enter 'x' for exit.")
	len1 = input("Enter length of first side: ")
	len2 = input("Enter length of second side: ")
	len3 = input("Enter length of third side: ")
	if len1 == 'x':
		break
	else:
		length1 = int(len1)
		length2 = int(len2)
		length3 = int(len3)
		perimeter = length1 + length2 + length3
		print("Perimeter of Triangle =", perimeter,"\n")

Here is the sample run of the above Python program to show how to calculate perimeter of a triangle:

python calculate perimeter of triangle

« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test