1. Hello World Program
This is the simplest program to get started with Python.
# Program to print Hello World
print("Hello, World!")Copy
2. Simple Calculator
A calculator to perform basic arithmetic operations.
# Program to create a simple calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operator = input("Enter operation (+, -, *, /): ")
if operator == '+':
print(f"Result: {num1 + num2}")
elif operator == '-':
print(f"Result: {num1 - num2}")
elif operator == '*':
print(f"Result: {num1 * num2}")
elif operator == '/':
print(f"Result: {num1 / num2}")
else:
print("Invalid operator")Copy
3. Find the Largest of Three Numbers
This program helps in finding the largest number among three given numbers.
# Program to find the largest of three numbers
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))
if a >= b and a >= c:
print(f"Largest number is: {a}")
elif b >= a and b >= c:
print(f"Largest number is: {b}")
else:
print(f"Largest number is: {c}")Copy
4. Check Even or Odd
A basic program to check if a number is even or odd.
# Program to check if a number is even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is an even number")
else:
print(f"{num} is an odd number")Copy
5. Factorial of a Number
This program calculates the factorial of a given number.
# Program to find the factorial of a number
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print(f"Factorial of {num} is {factorial}")Copy
6. Sum of Natural Numbers
Find the sum of the first ‘n’ natural numbers.
# Program to find the sum of first n natural numbers
n = int(input("Enter a number: "))
sum_n = n * (n + 1) // 2
print(f"Sum of first {n} natural numbers is {sum_n}") Copy
7. Fibonacci Series
This program generates the Fibonacci series up to ‘n’ terms.
# Program to generate Fibonacci series up to n terms
n = int(input("Enter the number of terms: "))
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + bCopy
8. Armstrong Number
Check whether a given number is an Armstrong number.
# Program to check if a number is an Armstrong number
num = int(input("Enter a number: "))
sum_of_cubes = sum([int(digit)**3 for digit in str(num)])
if sum_of_cubes == num:
print(f"{num} is an Armstrong number")
else:
print(f"{num} is not an Armstrong number")Copy
9. Palindrome String
Check whether a given string is a palindrome.
# Program to check if a string is a palindrome
string = input("Enter a string: ")
if string == string[::-1]:
print(f"{string} is a palindrome")
else:
print(f"{string} is not a palindrome")Copy
10. Simple Interest Calculator
Calculate the simple interest on a given principal amount, rate, and time.
# Program to calculate simple interest
P = float(input("Enter the principal amount: "))
R = float(input("Enter the rate of interest: "))
T = float(input("Enter the time (in years): "))
SI = (P * R * T) / 100
print(f"Simple Interest is: {SI}")Copy
11. Reverse a Number
This program reverses a given number.
# Program to reverse a number
num = int(input("Enter a number: "))
reversed_num = int(str(num)[::-1])
print(f"Reversed number is: {reversed_num}")Copy
12. Sum of Digits of a Number
Find the sum of digits of a given number.
# Program to find the sum of digits of a number
num = int(input("Enter a number: "))
sum_of_digits = sum([int(digit) for digit in str(num)])
print(f"Sum of digits is: {sum_of_digits}")Copy
13. Swapping Two Numbers
Swap two numbers without using a third variable.
# Program to swap two numbers without using a third variable
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = b, a
print(f"After swapping, first number: {a}, second number: {b}") Copy
14. Count Vowels in a String
Count the number of vowels in a string.
# Program to count the number of vowels in a string
string = input("Enter a string: ")
vowels = 'aeiouAEIOU'
count = sum(1 for char in string if char in vowels)
print(f"Number of vowels in the string: {count}")Copy
15. Check for Prime Number
This program checks whether a number is prime or not.
# Program to check if a number is prime
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, num):
if num % i == 0:
print(f"{num} is not a prime number")
break
else:
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")Copy
16. GCD of Two Numbers
Find the greatest common divisor (GCD) of two numbers.
# Program to find the GCD of two numbers
def gcd(a, b):
while b:
a, b = b, a % b
return a
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print(f"GCD of {num1} and {num2} is {gcd(num1, num2)}")Copy
17. List Operations (Append, Remove, Sort)
Perform basic list operations like append, remove, and sort.
# Program to perform list operations
numbers = [10, 20, 30, 40]
# Append
numbers.append(50)
print("List after appending:", numbers)
# Remove
numbers.remove(20)
print("List after removing:", numbers)
# Sort
numbers.sort()
print("List after sorting:", numbers)Copy
18. Matrix Addition
Add two 2×2 matrices.
# Program to add two 2x2 matrices
matrix1 = [[1, 2], [3, 4]]
matrix2 = [[5, 6], [7, 8]]
result = [[matrix1[i][j] + matrix2[i][j] for j in range(2)] for i in range(2)]
print("Resultant Matrix:")
for row in result:
print(row)Copy
19. Linear Search
Implement linear search to find an element in a list.
# Program to implement linear search
numbers = [10, 20, 30, 40, 50]
search_element = int(input("Enter element to search: "))
for index, value in enumerate(numbers):
if value == search_element:
print(f"Element found at index {index}")
break
else:
print("Element not found")Copy
20. Bubble Sort
Sort a list using the bubble sort algorithm.
# Program to implement bubble sort
numbers = [64, 34, 25, 12, 22, 11, 90]
for i in range(len(numbers)):
for j in range(0, len(numbers) - i - 1):
if numbers[j] > numbers[j + 1]:
numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]
print("Sorted list is:", numbers)Copy
These Python programs are perfect for your CBSE Class 11 Practical File and
cover fundamental topics in Python programming. Working through these
examples will not only enhance your understanding of core concepts but also
prepare you well for exams and real-world coding scenarios. Happy coding!
Share: