codescracker


python

Python Program to Calculate Perimeter of Rectangle



« Previous Program Next Program »


Calculate Perimeter of Rectangle in Python

To calculate perimeter of rectangle in python, you have to ask from user to enter length and breadth of rectangle to calculate and print the perimeter of that rectangle as shown in the program given below.

Python Programming Code to Calculate Perimeter of Rectangle

Following python program ask from user to enter length and breadth of rectangle to find perimeter:

# Python Program - Calculate Perimeter of Rectangle
		
while True:
	print("Enter 'x' for exit.")
	leng = input("Enter length of rectangle: ")
	brea = input("Enter breadth of rectangle: ")
	if leng == 'x':
		break
	else:
		length = int(leng)
		breadth = int(brea)
		perimeter = (2*length) + (2*breadth)
		print("Perimeter of Rectangle =", perimeter, "\n")

Here is the sample run of the above Python program shows how to calculate perimeter of rectangle:

python calculate perimeter of rectangle

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test