0% found this document useful (0 votes)
7 views4 pages

Python Programs For Lab Practicals

Uploaded by

Deepa John
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
7 views4 pages

Python Programs For Lab Practicals

Uploaded by

Deepa John
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

PYTHON PROGRAM

1.Write a program to enter two integers and perform all


arithmetic operations.
Ans.
a=int(input("enter the value of a: "))
b=int(input("enter the value of b: "))
print("The value of a+b is= ",(a+b))
print("The value of a-b is= ",(a-b))
print("The value of a*b is= ",(a*b))
print("The value of a/b is= ",(a/b))
print("The value of a%b is= ",(a%b))
OUTPUT
enter the value of a: 45
enter the value of b: 8
The value of a+b is= 53
The value of a-b is= 37
The value of a*b is= 360
The value of a/b is= 5.625
The value of a%b is= 5

2. Write a Python program to calculate the amount payable if


money has been lent on simple interest.
Principal or money lent = P, Rate of interest = R% per annum and
Time = T years. Then Simple Interest SI) = (P x R x T)/ 100.
Amount payable = Principal + SI.
Ans.
P=float(input("enter the principal amount:"))
R=float(input("enter the interest rate:"))
T=float(input("enter the time in years:"))
SI=(P*R*T)/100
Amount_Payable=P+SI
print("Amount payable is: Rs.",Amount_Payable)

OUTPUT:
enter the principal amount:100000
enter the interest rate:8
enter the time in years:3
The Simple Interest Will be: 24000.0
Amount payable is: Rs. 124000.0

3. Write a python program to find the area of a rectangle and


perimeter of a Square.
# Area of Rectangle
l=int(input("Enter the length:"))
b=int(input("Enter the breath:"))
area=l*b
print("The area of Rectangle is :",(area))
#Perimeter of a Square
s=int(input("Enter the value of Side:"))
Perimeter=4*s
print("The Perimeter of a square is:",Perimeter)

OUTPUT:
Enter the length:8
Enter the breath:7
The area of Rectangle is : 56
Enter the value of Side:9
The Perimeter of a square is: 36
4.Write a program to swap two numbers using and without using
a third variable.
Ans.
Swapping without using third variable
a=int(input("enter the value of a: "))
b=int(input("enter the value of b: "))
a,b=b,a
print("a=",a)
print("b=",b)
OUTPUT:
enter the value of a: 10
enter the value of b: 8
a= 8
b= 10
Swapping using third variable
a=int(input("enter the value of a: "))
b=int(input("enter the value of b: "))
temp = a
a=b
b = temp
print("a=",a)
print("b=",b)
OUTPUT:
enter the value of a: 15
enter the value of b: 25
a= 25
b= 15
5. Write a Python Program to print maximum of given three
numbers.
a=int(input("Enter the value of a: "))
b=int(input("Enter the value of b: "))
c=int(input("Enter the value of c: "))
if a>b:
if a>c:
print("The Greatest Number is",a)
else:
print("The Greatest Number is",c)
elif b>c:
print("The Greatest Number is",b)
else:
print("The Greatest Number is",c)

OUTPUT:
Enter the value of a: 8
Enter the value of b: 9
Enter the value of c: 10
The Greatest Number is 10

6) Program to print n natural numbers


n = int(input("Please Enter any Number: "))
print("The List of Natural Numbers from 1 to", n , "are")
for i in range(1, n + 1):
print (i, end = ' ')# end=’ ‘ is for white space
OUTPUT
Please Enter any Number: 10
The List of Natural Numbers from 1 to 10 are
1 2 3 4 5 6 7 8 9 10

You might also like