All Python Programs

All Programs

Basic Python Programs

Simple Python programs

If Condition Programs

If condition based Python Programs 

Looping based programs

program based on for loop, while loop, range

Searching and Sorting

Python Searching Programs
Python Sorting Programs

Python program to calculate and print the area and perimeter of the rectangle.

Solution with out using functions
Solution using functions without passing arguments
Solution using functions and by passing arguments
Solution using functions by passing arguments and returing multiple values


Solution : Without using function
Program/Source Code

l=int(input("Enter length of rectangle "))
b=int(input("Enter breadth of rectangle "))
a=l*b
p=2*(l+b)
print("Area = ",a)
print("Perimeter = ",p)

Output:

Enter length of rectangle 2
Enter breadth of rectangle 3
Area = 6
Perimeter = 10
>>>



Solution : Using function Without Passing Arguments
Program/Source Code

#function definition
def rectangle():
    l=int(input("Enter length of rectangle "))
    b=int(input("Enter breadth of rectangle "))
    a=l*b
    p=2*(l+b)
    print("Area = ",a)
    print("Perimeter = ",p)

#function definition
rectangle()

Output:

Enter length of rectangle 3
Enter breadth of rectangle 6
Area = 18
Perimeter = 18
>>>



Solution : Using function Passing Arguments
Program/Source Code

#function definition
def rectangle(l,b):
    a=l*b
    p=2*(l+b)
    print("Area = ",a)
    print("Perimeter = ",p)

#function definition
l=int(input("Enter length of rectangle "))
b=int(input("Enter breadth of rectangle "))
rectangle(l,b)

Output:

Enter length of rectangle 4
Enter breadth of rectangle 5
Area = 20
Perimeter = 18
>>>



Solution : Using function Passing Arguments and returing multiple values
Program/Source Code

#function definition
def rectangle(l,b):
    a=l*b
    p=2*(l+b)
    return a,p

#function definition
l=int(input("Enter length of rectangle "))
b=int(input("Enter breadth of rectangle "))
a,p=rectangle(l,b)
print("Area = ",a)
print("Perimeter = ",p)

Output:

Enter length of rectangle 5
Enter breadth of rectangle 6
Area = 30
Perimeter = 22
>>>

Previous :Python program to calculate and print area and perimeter of square

Next :Python program to calculate and print area and circumference of circle

You May Also Like:

Python Program to print table of a number
Python Program of Binary search
Python Program to Find Factorial of Number Using Loop
C Language Program to Print Fibonacci Series
Python Program to convert upper case alphabet to lower case alphabet
C Language Program for Prime Number

Tutorials

Technical Questions and Important programs

Interview Questions

C Programming
C++ Programming
Basic Python Tutorial
Advanced Python Tutorial
C Language
C++ Programming
Python programming
C Important Programs
C Interview Questions
C++ Interview Questions
Python Interview Questions
HTML Interview Questions


Visitor Counter

0142303