0% found this document useful (0 votes)
294 views

Python Lab Manual With Output Alg FC A

Uploaded by

paiprashanth92
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
294 views

Python Lab Manual With Output Alg FC A

Uploaded by

paiprashanth92
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

I PUC Computer Science Python programs PART A

Sri Adichunchanagiri independent PU College, shivamogga


Department of computer science
Practical laboratory manual
I puc 2024-25

1) Write a program to swap two numbers using a third variable.


Program:
a = int(input("Enter first number "))
b = int(input("Enter second number "))
print ("Values of variables before swapping ")
print ("Value of a =", a)
print ("Value of b =", b)
temp = a
a=b
b = temp
print("Values of variables after swapping")
print("Value of a =", a)
print("Value of b =", b)

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

Dept. of Computer Science, SAIPUC, Shivamogga 1


I PUC Computer Science Python programs PART A

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)

Dept. of Computer Science, SAIPUC, Shivamogga 2


I PUC Computer Science Python programs PART A

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

Dept. of Computer Science, SAIPUC, Shivamogga 3


I PUC Computer Science Python programs PART A

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

Dept. of Computer Science, SAIPUC, Shivamogga 4


I PUC Computer Science Python programs PART A

5) Write a Python program to find largest among three numbers.


Program:
num1 = float(input("Enter first number "))
num2 = float(input("Enter second number "))
num3 = float(input("Enter third number "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is ”,largest)

Output:
Enter first number 8
Enter second number 5
Enter third number 9
The largest number is 9.0

Dept. of Computer Science, SAIPUC, Shivamogga 5


I PUC Computer Science Python programs PART A

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

Dept. of Computer Science, SAIPUC, Shivamogga 6


I PUC Computer Science Python programs PART A

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

Dept. of Computer Science, SAIPUC, Shivamogga 7


I PUC Computer Science Python programs PART A

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

Dept. of Computer Science, SAIPUC, Shivamogga 8


I PUC Computer Science Python programs PART 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

Dept. of Computer Science, SAIPUC, Shivamogga 9


I PUC Computer Science Python programs PART A

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

Dept. of Computer Science, SAIPUC, Shivamogga 10


I PUC Computer Science Python programs PART A

11) Write a program to check whether an input number is a palindrome or not.


Program:
n = int(input("Enter a number "))
temp = n
reverse = 0
while(n>0):
digit = n % 10
reverse = reverse*10 + digit
n = n // 10
if(temp == reverse):
print("Palindrome")
else:
print("Not a Palindrome“)

Output:
Enter a number 131
Palindrome

Dept. of Computer Science, SAIPUC, Shivamogga 11


I PUC Computer Science Python programs PART A

12) Write a python program to print the following patterns:


12345
1234
123
12
1
Program:
rows = int(input("Enter the number of rows "))
for i in range(rows,0,-1):

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

Dept. of Computer Science, SAIPUC, Shivamogga 12

You might also like