CBSE 2026
Important IP Programs
Master your practical exams with our curated list of essential Python and SQL programs for Class 11. Click on any question to view the code, copy it, or run it instantly.
Python 3
# This is a comment. It is ignored by Python.
print("Hello, Class 11 IP Students!")
Python 3
name = "Amit" # String
age = 16 # Integer
height = 5.8 # Float
print("Name:", name)
print("Age:", age)
print("Height:", height)
Python 3
x = 10
y = 10.5
z = "Hello"
print(type(x)) # <class 'int'>
print(type(y)) # <class 'float'>
print(type(z)) # <class 'str'>
Python 3
a = 10
b = 3
print("Add:", a + b)
print("Sub:", a - b)
print("Mul:", a * b)
print("Div:", a / b) # Returns float
Python 3
a = 10
b = 3
print("Floor Div (Quotient):", a // b) # 3
print("Modulus (Remainder):", a % b) # 1
Python 3
base = 2
power = 3
print("2 to the power 3 is:", base ** power) # 8
Python 3
name = input("Enter your name: ")
print("Welcome,", name)
Python 3
# input() returns string, wrap in int()
age = int(input("Enter your age: "))
print("Next year you will be:", age + 1)
Python 3
price = float(input("Enter price: "))
print("Price is:", price)
Python 3
a = 5
b = 10
print("Before:", a, b)
# Pythonic way to swap
a, b = b, a
print("After:", a, b)
Python 3
x = 10
y = 20
print("x > y is", x > y) # False
print("x == y is", x == y) # False
print("x != y is", x != y) # True
Python 3
a = True
b = False
print("a and b:", a and b) # False
print("a or b:", a or b) # True
print("not a:", not a) # False
Python 3
count = 10
count += 5 # Same as count = count + 5
print("Count:", count) # 15
Python 3
p = float(input("Principal: "))
r = float(input("Rate: "))
t = float(input("Time: "))
si = (p * r * t) / 100
print("Simple Interest:", si)
Python 3
PI = 3.14159
radius = float(input("Radius: "))
area = PI * radius * radius
print("Area:", area)
Python 3
x = 10
print("ID of x:", id(x))
x = 20 # Creates new object, doesn't change old one
print("ID of x (new):", id(x))
Python 3
num_int = 123
num_float = 1.23
# Python converts int to float to avoid data loss
result = num_int + num_float
print("Result type:", type(result))
Python 3
# Mul (*) happens before Add (+)
res = 10 + 2 * 3
print("10 + 2 * 3 =", res) # 16, not 36
Python 3
s = "Ha"
print(s * 3) # HaHaHa
Python 3
print("A", "B", "C", sep="-")
print("Hello", end=" ") # Stays on same line
print("World")
Python 3
x = 10
if x > 5:
print("x is greater than 5")
Python 3
n = int(input("Enter number: "))
if n >= 0:
print("Positive")
else:
print("Negative")
Python 3
n = int(input("Enter number: "))
if n % 2 == 0:
print("Even")
else:
print("Odd")
Python 3
marks = int(input("Enter marks: "))
if marks >= 90:
print("A Grade")
elif marks >= 75:
print("B Grade")
elif marks >= 50:
print("C Grade")
else:
print("Fail")
Python 3
a = 10
b = 25
c = 15
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")
Python 3
y = int(input("Year: "))
if (y % 400 == 0) or (y % 4 == 0 and y % 100 != 0):
print("Leap Year")
else:
print("Not Leap Year")
Python 3
for i in range(5):
print(i)
Python 3
# Range goes up to stop-1
for i in range(1, 11):
print(i, end=" ")
Python 3
# Start at 2, end before 11, step 2
for i in range(2, 11, 2):
print(i, end=" ")
Python 3
n = 5
while n > 0:
print(n)
n = n - 1 # Decrease count
print("Blastoff!")
Python 3
n = 10
total = 0
for i in range(1, n + 1):
total += i
print("Sum is:", total)
Python 3
num = 5
fact = 1
for i in range(1, num + 1):
fact = fact * i
print("Factorial:", fact)
Python 3
n = 5
for i in range(1, 11):
print(n, "x", i, "=", n*i)
Python 3
for i in range(1, 10):
if i == 5:
break # Stops at 5
print(i, end=" ")
Python 3
for i in range(1, 6):
if i == 3:
continue # Skips printing 3
print(i, end=" ")
Python 3
for i in range(1, 4): # Rows
for j in range(i): # Columns
print("*", end="")
print() # Newline
Python 3
for i in range(3):
print(i)
else:
print("Loop finished successfully")
Python 3
fruits = ["Apple", "Banana", "Cherry"]
print(fruits)
Python 3
nums = [10, 20, 30]
print("First:", nums[0])
print("Last:", nums[-1]) # Negative indexing
Python 3
# Indices: 0 1 2 3 4
data = [10, 20, 30, 40, 50]
print(data[1:4]) # [20, 30, 40]
Python 3
colors = ["Red", "Green", "Blue"]
for c in colors:
print(c)
Python 3
nums = [1, 2, 3]
nums[1] = 99 # Change 2 to 99
print(nums)
Python 3
l = [10, 20, 30]
print("Length:", len(l))
Python 3
l = [1, 2]
l.append(3)
print(l)
Python 3
l = [1, 2]
l.extend([3, 4])
print(l)
Python 3
l = [10, 30]
l.insert(1, 20) # Insert 20 at index 1
print(l)
Python 3
l = [10, 20, 30]
val = l.pop(1) # Removes 20
print("Popped:", val)
print("List:", l)
Python 3
l = [1, 2, 3, 2]
l.remove(2) # Removes first '2'
print(l)
Python 3
l = ['a', 'b', 'c']
print("Index of b:", l.index('b'))
Python 3
l = [1, 2, 1, 1, 3]
print("Count of 1:", l.count(1))
Python 3
l = [1, 2, 3]
l.reverse()
print(l)
Python 3
l = [3, 1, 2]
l.sort()
print(l)
Python 3
nums = [10, 5, 20]
print("Min:", min(nums))
print("Max:", max(nums))
print("Sum:", sum(nums))
Python 3
l1 = [1, 2]
l2 = [3, 4]
print(l1 + l2)
Python 3
l = ["Hi"]
print(l * 3)
Python 3
l = [10, 20, 30]
if 20 in l:
print("Found")
Python 3
s = "A-B-C"
l = s.split("-")
print(l)
Python 3
# Key: Value
student = {"Name": "Rahul", "Age": 16}
print(student)
Python 3
d = {"Apple": 100, "Mango": 80}
print("Price of Apple:", d["Apple"])
Python 3
d = {"a": 1}
d["b"] = 2
print(d)
Python 3
d = {"x": 10}
d["x"] = 20
print(d)
Python 3
d = {"a": 1, "b": 2}
del d["a"]
print(d)
Python 3
d = {"Name": "A", "Age": 16}
print(d.keys())
Python 3
d = {"Name": "A", "Age": 16}
print(d.values())
Python 3
d = {"x": 1, "y": 2}
print(d.items())
Python 3
d = {"a": 1, "b": 2}
for k in d:
print(k, "->", d[k])
Python 3
d = {"a": 1, "b": 2}
for val in d.values():
print(val)
Python 3
d = {"a": 100, "b": 200}
for k, v in d.items():
print("Key:", k, "Value:", v)
Python 3
d = {1: "one", 2: "two"}
print(len(d))
Python 3
d = {"a": 1}
d.clear()
print(d) # {}
Python 3
d1 = {"a": 1}
d2 = {"b": 2}
d1.update(d2)
print(d1)
Python 3
data = [("a", 1), ("b", 2)]
d = dict(data)
print(d)
Python 3
d = {"name": "Simran"}
if "name" in d:
print("Key exists")
Python 3
import numpy as np
print("NumPy imported")
Python 3
import numpy as np
l = [1, 2, 3]
arr = np.array(l)
print(arr)
Python 3
import numpy as np
l = [[1, 2], [3, 4]]
arr = np.array(l)
print(arr)
Python 3
import numpy as np
arr = np.array([1, 2, 3])
print("Dimensions:", arr.ndim)
Python 3
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print("Shape:", arr.shape)
Python 3
import numpy as np
arr = np.array([1.5, 2.5])
print("Type:", arr.dtype)
Python 3
import numpy as np
arr = np.array([1, 2, 3], dtype='float')
print(arr)
Python 3
import numpy as np
arr = np.arange(5) # 0 to 4
print(arr)
Python 3
import numpy as np
z = np.zeros(5)
print(z)
Python 3
import numpy as np
o = np.ones(5)
print(o)
Python 3
import numpy as np
arr = np.array([10, 20])
print(arr + 5) # Adds 5 to all
Python 3
import numpy as np
a = np.array([1, 2])
b = np.array([10, 20])
print(a + b)
Python 3
import numpy as np
a = np.array([2, 3])
b = np.array([4, 5])
print(a * b)
Python 3
import numpy as np
# 5 numbers between 0 and 1
l = np.linspace(0, 1, 5)
print(l)
Python 3
import numpy as np
arr = np.array([[1, 2], [3, 4]])
print("Size:", arr.size) # 4
Python 3
import numpy as np
arr = np.array([1, 2, 3], dtype='int32')
print("Bytes per item:", arr.itemsize)
Python 3
# print("Missing quote)
# The above line causes SyntaxError
print("Fixed Syntax")
Python 3
# print(undefined_var)
# NameError: name 'undefined_var' is not defined
print("Define variables before use.")
Python 3
msg = "Python"
print("P" in msg) # True
Python 3
f = "Data"
l = "Science"
print(f + " " + l)
Python 3
a = [1, 2, 3]
b = list(a) # Creates new copy
print(b)
Python 3
matrix = [[1, 2], [3, 4]]
print(matrix[0][1]) # 2
Python 3
d = {"a": 1}
# Returns None if key missing, instead of error
print(d.get("b"))
Python 3
d = {"a": 1}
d.setdefault("b", 0) # Sets b to 0 if missing
print(d)
Python 3
keys = ['a', 'b', 'c']
d = dict.fromkeys(keys, 0)
print(d)
Python 3
l = []
if not l:
print("List is empty")
Python 3
name = "Ali"
score = 90
print(f"{name} scored {score}")