Program 1: Factorial using Function
def factorial(n): if n == 0 or n == 1: return 1 return n * factorial(n-1) num = 5 print("Factorial:",
factorial(num))
Output: Factorial: 120
Program 2: Fibonacci Series
n = 7 a, b = 0, 1 for i in range(n): print(a, end=" ") a, b = b, a+b
Output: 0 1 1 2 3 5 8
Program 3: Palindrome Check
s = "madam" if s == s[::-1]: print("Palindrome") else: print("Not Palindrome")
Output: Palindrome
Program 4: File Write and Read
f = open("[Link]","w") [Link]("Hello CBSE") [Link]() f = open("[Link]","r") print([Link]()) [Link]()
Output: Hello CBSE
Program 5: Count Vowels
s = "computer" vowels = "aeiou" count = 0 for ch in s: if ch in vowels: count += 1 print("Vowels:",
count)
Output: Vowels: 3
Program 6: Dictionary Sorting
d = {'b':2,'a':1,'c':3} print(dict(sorted([Link]())))
Output: {'a': 1, 'b': 2, 'c': 3}
Program 7: Binary Search
arr = [1,3,5,7,9] key = 7 low, high = 0, len(arr)-1 found = False while low <= high: mid =
(low+high)//2 if arr[mid] == key: found = True break elif arr[mid] < key: low = mid+1 else: high =
mid-1 print("Found" if found else "Not Found")
Output: Found
Program 8: Matrix Addition
A = [[1,2],[3,4]] B = [[5,6],[7,8]] C = [[A[i][j]+B[i][j] for j in range(2)] for i in range(2)] print(C)
Output: [[6, 8], [10, 12]]
Program 9: Exception Handling
try: a = 10/0 except ZeroDivisionError: print("Cannot divide by zero")
Output: Cannot divide by zero
Program 10: CSV File Read
import csv with open("[Link]","w",newline='') as f: writer = [Link](f)
[Link](["Name","Marks"]) [Link](["Amit",85]) with open("[Link]","r") as f:
print([Link]())
Output: Name,Marks Amit,85