Python Lab Manual With Output Alg FC A
Python Lab Manual With Output Alg FC A
Output:
Enter first number 3
Enter second number 4
Values of variables before swapping
Value of a= 3
Value of b= 4
Values of variables after swapping
Value of a= 4
Value of b= 3
2) Write a python program to enter two integers and perform all arithmetic operations on them.
Program:
n1 = int(input("Enter first number "))
n2 = int(input("Enter second number "))
print("Printing the result for all arithmetic operations ")
print("Addition ",n1+n2)
print("Subtraction ",n1-n2)
print("Multiplication ",n1*n2)
print("Division ",n1/n2)
print("Modulus ", n1%n2)
3) Write a Python program to accept length and width of a rectangle and compute its perimeter and area.
Program:
length = float(input("Enter length of the rectangle "))
breadth = float(input("Enter breadth of the rectangle "))
area = length * breadth
perimeter = 2 * (length * breadth)
print("Area of rectangle = ", area)
print(" Perimeter of rectangle = ", perimeter)
Output:
Enter length of the rectangle 4
Enter breadth of the rectangle 2
Area of rectangle = 8.0
Perimeter of rectangle = 16.0
4) 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.
P, R and T are given as input to the program.
Program:
principal = float(input('Enter amount '))
time = float(input('Enter time '))
rate = float(input('Enter rate '))
si = (principal*time*rate)/100
print('Simple interest is ',si)
Output:
Enter amount 1000
Enter time 3
Enter rate 2
Simple interest is 60.0
Output:
Enter first number 8
Enter second number 5
Enter third number 9
The largest number is 9.0
6) Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a
driving license or not. (The eligible age is 18 years).
Program:
name = input("Enter your name ")
age = int(input("Enter your age "))
if age >= 18:
print("You are eligible to apply for the driving license ")
else:
print("You are not eligible to apply for the driving license ")
Output:
Enter your name anil
Enter your age 16
You are not eligible to apply for the driving license
Algorithm:
Step 1: Start
Step 2: input name and age
Step 3: if age > = 18
print eligible to apply for driving license
else
print not eligible to apply for driving license
Step 4: Stop
7) Write a program that prints minimum and maximum of five numbers entered by the user.
Program:
smallest = 0
largest = 0
for a in range(0,5):
x = int(input("Enter the number "))
if a == 0:
smallest = largest = x
if(x < smallest):
smallest = x
if(x > largest):
largest = x
print("The smallest number is ",smallest)
print("The largest number is ”,largest)
Output:
Enter the number 4
Enter the number 7
Enter the number 1
Enter the number 9
Enter the number 5
The smallest number is 1
The largest number is 9
8) Write a python program to find the grade of a student when grades are allocated as given in the table below. Percentage of Marks
Grade
Above 90% A
80% to 90% B
70% to 80% C
60% to 70% D
Below 60% E
Percentage of the marks obtained by the student is input to the program.
Program:
p = float(input('Enter the percentage '))
if(p > 90):
print("Grade A")
elif(p > 80):
print("Grade B")
elif(p > 70):
print("Grade C")
elif(p >= 60):
print("Grade D")
else:
print("Grade E")
Output:
Enter the percentage 95
Grade A
9) Write a python program to print the table of a given number. The number has to be entered by the user
Program:
num = int(input("Enter the number "))
count = 1
while count <= 10:
prd = num * count
print(num, 'x', count, '=', prd)
count += 1
10) Write a program to find the sum of digits of an integer number, input by the user
Program:
sum = 0
n = int(input("Enter the number "))
while n > 0:
digit = n % 10
sum = sum + digit
n = n//10
print("The sum of digits of the number is ",sum)
Output:
Enter the number 12
The sum of digits of the number is 3
Output:
Enter a number 131
Palindrome
for j in range(1,i+1):
print(j, end=" ")
print()
Algorithm:
Step 1: Start
Step 2: input number rows r
Step 3: for i in range (r, 0, -1):
for j in range (1,i+1):
print(j,end=” “)
print( )
Step 4: Stop
Output:
Enter the number of rows 5
12345
1234
123
12
1