PM SHRI KENDRIYA VIDYALAYA
BAMANGACHI
(School Code: 19208 | KV Code: 1262)
PYTHON PROGRAMMING
Practical Assignment
Session: 2025-26
Class: IX & X (CBSE)
Subject: Computer Science / Artificial Intelligence
Student Details
Name:
Class & Sec: Roll No:
PM SHRI KV BAMANGACHI Computer Science / AI
Contents
1 Introduction 2
2 Unit 1: Input, Output & Variables 2
3 Unit 2: Conditional Statements (if-else) 3
4 Unit 3: Loops (For & While) 5
5 Unit 4: Strings & Lists 7
6 Unit 5: Advanced & Miscellaneous 9
7 Practice Bank by Difficulty Level 11
7.1 Level 1: Basic (Variables & Operators) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7.2 Level 2: Easy (Conditionals) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7.3 Level 3: Medium (Loops & Lists) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7.4 Level 4: Advanced (Nested Logic) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1
PM SHRI KV BAMANGACHI Computer Science / AI
1 Introduction
This assignment covers the fundamental concepts of Python Programming prescribed by CBSE for
Class 9 and 10. Students are required to write these codes in their practical file and verify the output.
2 Unit 1: Input, Output & Variables
Prog #1: Hello World
Write a program to print a welcome message.
print("Welcome to PM SHRI KV Bamangachi")
print("Python is fun!")
Prog #2: Addition of Two Numbers
Accept two numbers from the user and print their sum.
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("Sum:", num1 + num2)
Prog #3: Area of a Rectangle
Calculate the area of a rectangle using user input.
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
area = l * b
print("Area of Rectangle:", area)
Prog #4: Simple Interest Calculator
Calculate Simple Interest (SI = P*R*T/100).
p = float(input("Principal Amount: "))
r = float(input("Rate of Interest: "))
t = float(input("Time (years): "))
si = (p * r * t) / 100
print("Simple Interest:", si)
Prog #5: Swapping Variables
Swap two numbers using a third variable.
a = 10
b = 20
temp = a
a = b
b = temp
print("After swapping: a =", a, "b =", b)
2
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #6: Swap Without Third Variable
Swap two numbers without using a temporary variable.
x = 5
y = 10
x, y = y, x
print("x =", x, "y =", y)
Prog #7: Kilometers to Miles
Convert distance from Kilometers to Miles (1 KM = 0.621371 Miles).
km = float(input("Enter value in KM: "))
miles = km * 0.621371
print(km, "km is equal to", miles, "miles")
Prog #8: Calculate Average
Find the average of three marks.
m1 = 80
m2 = 90
m3 = 85
avg = (m1 + m2 + m3) / 3
print("Average Marks:", avg)
Prog #9: Square and Cube
Find the square and cube of a number.
n = int(input("Enter a number: "))
print("Square:", n ** 2)
print("Cube:", n ** 3)
Prog #10: Input Personal Details
Take name and age as input and print them.
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name, "you are", age, "years old.")
3 Unit 2: Conditional Statements (if-else)
Prog #11: Check Even or Odd
Check if a number is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")
3
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #12: Positive, Negative or Zero
Check the nature of a number.
n = int(input("Enter number: "))
if n > 0:
print("Positive")
elif n < 0:
print("Negative")
else:
print("Zero")
Prog #13: Voting Eligibility
Check if a person is eligible to vote (Age >= 18).
age = int(input("Enter age: "))
if age >= 18:
print("Eligible to Vote")
else:
print("Not Eligible")
Prog #14: Largest of Two Numbers
Find the larger of two numbers.
a = 10
b = 25
if a > b:
print(a, "is greater")
else:
print(b, "is greater")
Prog #15: Largest of Three Numbers
Find the largest among three numbers.
a = int(input("A: "))
b = int(input("B: "))
c = int(input("C: "))
if a > b and a > c:
print("A is largest")
elif b > a and b > c:
print("B is largest")
else:
print("C is largest")
Prog #16: Leap Year Check
Check if a year is a leap year.
year = int(input("Enter year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
4
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #17: Grade Calculation
Assign grades based on marks.
marks = float(input("Marks: "))
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")
Prog #18: Divisibility Check
Check if a number is divisible by both 5 and 11.
n = int(input("Enter number: "))
if n % 5 == 0 and n % 11 == 0:
print("Divisible by 5 and 11")
else:
print("Not Divisible")
Prog #19: Vowel or Consonant
Check if a character is a vowel.
char = input("Enter char: ").lower()
if char in 'aeiou':
print("Vowel")
else:
print("Consonant")
Prog #20: Simple Calculator
Perform operation based on user choice.
a = 10; b = 5
op = input("Enter operator (+, -, *, /): ")
if op == '+': print(a + b)
elif op == '-': print(a - b)
elif op == '*': print(a * b)
elif op == '/': print(a / b)
else: print("Invalid Operator")
4 Unit 3: Loops (For & While)
Prog #21: Print 1 to 10
Print numbers from 1 to 10 using a loop.
for i in range(1, 11):
print(i, end=" ")
5
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #22: Multiplication Table
Print the table of a given number.
n = int(input("Enter number: "))
for i in range(1, 11):
print(n, "x", i, "=", n*i)
Prog #23: Sum of Natural Numbers
Calculate sum of first N natural numbers.
n = 10
total = 0
for i in range(1, n+1):
total += i
print("Sum:", total)
Prog #24: Factorial of a Number
Find factorial (e.g., 5! = 120).
n = 5
fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial:", fact)
Prog #25: Reverse a Loop
Print numbers from 10 down to 1.
for i in range(10, 0, -1):
print(i, end=" ")
Prog #26: While Loop Example
Print ’Hello’ 5 times using while loop.
i = 1
while i <= 5:
print("Hello")
i += 1
Prog #27: Fibonacci Series
Print first 10 terms of Fibonacci series.
a, b = 0, 1
print(a, b, end=" ")
for i in range(8):
c = a + b
print(c, end=" ")
a = b
b = c
6
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #28: Check Prime Number
Check if a number is prime.
n = int(input("Enter number: "))
count = 0
for i in range(1, n+1):
if n % i == 0:
count += 1
if count == 2: print("Prime")
else: print("Not Prime")
Prog #29: Sum of Digits
Calculate sum of digits of a number (e.g., 123 → 6).
n = 123
s = 0
while n > 0:
rem = n % 10
s += rem
n = n // 10
print("Sum of digits:", s)
Prog #30: Reverse a Number
Reverse a given integer.
n = 1234
rev = 0
while n > 0:
rem = n % 10
rev = (rev * 10) + rem
n = n // 10
print("Reverse:", rev)
5 Unit 4: Strings & Lists
Prog #31: String Traversal
Print each character of a string.
s = "PYTHON"
for char in s:
print(char)
Prog #32: Count Vowels in String
Count how many vowels are in a string.
text = "Education"
count = 0
for char in [Link]():
if char in 'aeiou':
count += 1
7
PM SHRI KV BAMANGACHI Computer Science / AI
print("Vowels:", count)
Prog #33: Palindrome Check (String)
Check if a string is a palindrome (e.g., MADAM).
s = input("Enter word: ")
if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
Prog #34: Create a List
Create a list of 5 numbers and print it.
L = [10, 20, 30, 40, 50]
print("List:", L)
print("First Element:", L[0])
Prog #35: Sum of List Elements
Find sum of numbers in a list.
nums = [5, 10, 15, 20]
print("Sum:", sum(nums))
Prog #36: Largest and Smallest
Find max and min values in a list.
vals = [23, 1, 45, 88, 12]
print("Max:", max(vals))
print("Min:", min(vals))
Prog #37: Linear Search
Search for a number in a list.
L = [10, 20, 30, 40]
key = 30
if key in L:
print("Found")
else:
print("Not Found")
Prog #38: Sort a List
Sort a list in ascending order.
L = [5, 2, 9, 1, 5, 6]
[Link]()
print("Sorted:", L)
8
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #39: List Slicing
Extract a part of a list.
L = ['a', 'b', 'c', 'd', 'e']
print(L[1:4]) # Prints 'b', 'c', 'd'
Prog #40: Append to List
Add an element to an existing list.
fruits = ["Apple", "Banana"]
[Link]("Mango")
print(fruits)
6 Unit 5: Advanced & Miscellaneous
Prog #41: Pattern Printing 1
Print a star triangle.
rows = 5
for i in range(1, rows + 1):
print("*" * i)
Prog #42: Pattern Printing 2
Print a number triangle.
# 1
# 22
# 333
for i in range(1, 4):
print(str(i) * i)
Prog #43: Random Number
Generate a random number (dice roll).
import random
print("Dice Roll:", [Link](1, 6))
Prog #44: Math Module
Use math module to find square root.
import math
print("Sqrt of 16:", [Link](16))
print("Value of Pi:", [Link])
9
PM SHRI KV BAMANGACHI Computer Science / AI
Prog #45: Dictionary Basics
Create a dictionary of student marks.
marks = {"Rahul": 90, "Amit": 85, "Sneha": 95}
print("Rahul's marks:", marks["Rahul"])
Prog #46: Def Function
Create a function to greet a user.
def greet(name):
print("Hello,", name)
greet("Student")
Prog #47: Function with Return
Function to add two numbers.
def add(x, y):
return x + y
res = add(5, 7)
print("Result:", res)
Prog #48: Armstrong Number
Check if a number is Armstrong (153 = 13 + 53 + 33 ).
num = 153
temp = num
s = 0
while temp > 0:
d = temp % 10
s += d ** 3
temp //= 10
if num == s: print("Armstrong")
Prog #49: Break Statement
Stop loop when a condition is met.
for i in range(1, 10):
if i == 5:
break
print(i, end=" ")
Prog #50: Continue Statement
Skip an iteration in a loop.
for i in range(1, 6):
if i == 3:
continue
print(i, end=" ")
10
PM SHRI KV BAMANGACHI Computer Science / AI
7 Practice Bank by Difficulty Level
7.1 Level 1: Basic (Variables & Operators)
Prog #51: Perimeter of Rectangle
Calculate the perimeter of a rectangle.
l = float(input("Length: "))
b = float(input("Breadth: "))
p = 2 * (l + b)
print("Perimeter:", p)
Prog #52: Days to Seconds
Convert number of days into seconds.
days = int(input("Enter days: "))
seconds = days * 24 * 60 * 60
print("Seconds:", seconds)
7.2 Level 2: Easy (Conditionals)
Prog #53: Electricity Bill Calculator
Calculate bill: First 100 units free, else Rs. 5/unit.
units = int(input("Enter units: "))
if units <= 100:
bill = 0
else:
bill = (units - 100) * 5
print("Total Bill: Rs.", bill)
Prog #54: Character Case Check
Check if a character is uppercase or lowercase.
ch = input("Enter char: ")
if ch >= 'A' and ch <= 'Z':
print("Uppercase")
elif ch >= 'a' and ch <= 'z':
print("Lowercase")
else:
print("Other symbol")
7.3 Level 3: Medium (Loops & Lists)
Prog #55: Second Largest Number
Find the second largest number in a list without sorting.
L = [10, 20, 4, 45, 99]
mx = max(L[0], L[1])
second = min(L[0], L[1])
11
PM SHRI KV BAMANGACHI Computer Science / AI
for i in range(2, len(L)):
if L[i] > mx:
second = mx
mx = L[i]
elif L[i] > second and L[i] != mx:
second = L[i]
print("Second Largest:", second)
Prog #56: Count Frequencies
Count occurrence of each character in a string.
s = "banana"
freq = {}
for i in s:
if i in freq:
freq[i] += 1
else:
freq[i] = 1
print(freq)
7.4 Level 4: Advanced (Nested Logic)
Prog #57: Prime Numbers in Range
Print all prime numbers between 1 and 50.
for num in range(2, 51):
is_prime = True
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=" ")
Prog #58: Floyd’s Triangle
Print Floyd’s Triangle.
rows = 4
num = 1
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(num, end=" ")
num += 1
print()
12