INFORMATICS PRACTICES
GR 11 PYTHON Practical Programs to be written in Lab Record Book
Dear Students
PFA 17 Python lab record programs to write in the lab record.
Instructions:
• Write the problem statement and leave one line and write the source code on the ruled
side.
• All programs(source code) to be hand written.
• The output of each program is also given, which should be printed out(hardcopy) to be
stuck on the left side of the record book exactly across the respective program.
• All programs should be free of syntax errors and indentation errors.
• Submission Date for the above 17 Python programs is 06-10-25.
1. To find average and grade for given marks.
# To find average and grade for given marks.
marks = [78, 82, 69, 90, 88]
average = sum(marks) / len(marks)
if average >= 90:
grade = 'A'
elif average >= 80:
grade = 'B'
elif average >= 70:
grade = 'C'
elif average >= 60:
grade = 'D'
else:
grade = 'F'
print("Average:", average)
print("Grade:", grade)
Output:
Average: 81.4
Grade: B
2. To find the sale price of an item with given cost and discount (%).
# To find the sale price of an item with given cost and discount (%).
cost = 1200
discount_percent = 15
discount_amount = (discount_percent / 100) * cost
sale_price = cost - discount_amount
print("Sale Price:", sale_price)
Output:
Sale Price: 1020.0
3. To calculate the perimeter/circumference and area of shapes such as triangle,
rectangle, square, and circle.
# To calculate perimeter/circumference and area of triangle, rectangle, square, and
circle.
# Rectangle
length, width = 10, 5
rect_perimeter = 2 * (length + width)
rect_area = length * width
print("Rectangle: Perimeter =", rect_perimeter, ", Area =", rect_area)
# Square
side = 4
sq_perimeter = 4 * side
sq_area = side * side
print("Square: Perimeter =", sq_perimeter, ", Area =", sq_area)
# Circle
radius = 7
import math
circle_circum = 2 * [Link] * radius
circle_area = [Link] * radius ** 2
print("Circle: Circumference =", circle_circum, ", Area =", circle_area)
# Triangle (Equilateral)
side = 6
tri_perimeter = 3 * side
tri_area = ([Link](3)/4) * side ** 2
print("Triangle (Equilateral): Perimeter =", tri_perimeter, ", Area =", tri_area)
Output:
Rectangle: Perimeter = 30 , Area = 50
Square: Perimeter = 16 , Area = 16
Circle: Circumference = 43.982297150257104 , Area = 153.93804002589985
Triangle (Equilateral): Perimeter = 18 , Area = 15.588457268119894
4. To calculate simple and compound interest.
# To calculate simple and compound interest.
principal = 5000
rate = 8 # percent
time = 2 # years
# Simple Interest
si = (principal * rate * time) / 100
# Compound Interest
ci = principal * ((1 + rate / 100) ** time) - principal
print("Simple Interest:", si)
print("Compound Interest:", ci)
Output:
Simple Interest: 800.0
Compound Interest: 832.0
5. To calculate profit-loss for given Cost and Sell Price.
# To calculate profit-loss for given Cost and Sell Price.
cp = 750
sp = 850
if sp > cp:
profit = sp - cp
print("Profit:", profit)
elif cp > sp:
loss = cp - sp
print("Loss:", loss)
else:
print("No profit, No loss")
Output:
Profit: 100
6. To calculate EMI for Amount, Period and Interest.
# To calculate EMI for Amount, Period and Interest.
P = 100000 # Principal
R = 10 / (12 * 100) # Monthly interest rate
N = 12 * 2 # Number of months
emi = (P * R * ((1 + R) ** N)) / (((1 + R) ** N) - 1)
print("EMI:", round(emi, 2))
Output:
EMI: 4614.46
7. To calculate tax - GST/Income Tax.
# To calculate tax - GST/Income Tax.
amount = 2000
gst_rate = 18 # percent
gst = (gst_rate / 100) * amount
total_amount = amount + gst
print("GST:", gst)
print("Total Amount after GST:", total_amount)
Output:
GST: 360.0
Total Amount after GST: 2360.0
8. To find the largest and smallest numbers in a list.
# To find the largest and smallest numbers in a list.
nums = [12, 45, 3, 67, 23, 89, 1, 54]
largest = max(nums)
smallest = min(nums)
print("Largest:", largest)
print("Smallest:", smallest)
Output:
Largest: 89
Smallest: 1
9. STo find the third largest/smallest number in a list.
# To find the third largest/smallest number in a list.
nums = [15, 43, 7, 89, 21, 57]
nums_sorted = sorted(nums)
third_smallest = nums_sorted[^1_2]
third_largest = nums_sorted[-3]
print("Third Smallest:", third_smallest)
print("Third Largest:", third_largest)
Output:
Third Smallest: 21
Third Largest: 43
10. To find the sum of squares of the first 100 natural numbers.
# To find the sum of squares of the first 100 natural numbers.
sum_sq = sum(i*i for i in range(1, 101))
print("Sum of squares:", sum_sq)
Output:
Sum of squares: 338350
11. To print the first n multiples of given number.
# To print the first n multiples of given number.
num = 7
n = 10
for i in range(1, n+1):
print(num * i, end=' ')
Output:
7 14 21 28 35 42 49 56 63 70
12. To count the number of vowels in user entered string.
# To count the number of vowels in user entered string.
string = "Programming in Python"
vowels = "aeiouAEIOU"
count = sum(1 for ch in string if ch in vowels)
print("Number of vowels:", count)
Output:
Number of vowels: 6
13. To print the words starting with a particular alphabet in a user entered string.
# To print the words starting with a particular alphabet in a user entered string.
string = "Python programming is powerful and popular"
alphabet = 'p'
words = [word for word in [Link]() if [Link]().startswith([Link]())]
print("Words starting with", alphabet, ":", words)
Output:
Words starting with p : ['Python', 'programming', 'powerful', 'popular']
14. To count number of occurrence of a given alphabet in a given string.
# To count number of occurrence of a given alphabet in a given string.
string = "Programming in Python"
alphabet = 'n'
count = [Link]().count([Link]())
print("Occurrences of", alphabet, ":", count)
Output:
Occurrences of n : 3
15. Create a dictionary to store names of states and their capitals.
# Create a dictionary to store names of states and their capitals.
states_capitals = {
"Maharashtra": "Mumbai",
"Karnataka": "Bengaluru",
"Tamil Nadu": "Chennai",
"West Bengal": "Kolkata"
}
print(states_capitals)
Output:
{'Maharashtra': 'Mumbai', 'Karnataka': 'Bengaluru', 'Tamil Nadu': 'Chennai', 'West
Bengal': 'Kolkata'}
16. Create dictionary of students to store names and marks obtained in 5 subjects.
# Create dictionary of students to store names and marks obtained in 5 subjects.
students = {
"Ankit": [78, 89, 92, 85, 74],
"Priya": [88, 79, 95, 91, 82]
}
print(students)
Output:
{'Ankit': [78, 89, 92, 85, 74], 'Priya': [88, 79, 95, 91, 82]}
17. To print the highest and lowest values in the dictionary.
# To print the highest and lowest values in the dictionary.
d = {'a': 34, 'b': 89, 'c': 23, 'd': 72}
highest = max([Link]())
lowest = min([Link]())
print("Highest value:", highest)
print("Lowest value:", lowest)
Output:
Highest value: 89
Lowest value: 23