Class 12 Python Programs Final v3
Class 12 Python Programs Final v3
This document contains a collection of 20+ Python programs based on the concepts taught in Class
12.
These programs cover various topics such as basic algorithms, object-oriented programming (OOP),
data structures,
The programs are numbered for easy reference and demonstrate the core concepts required in
This is to certify that Pranjal Agarwal, a student of Class 12, has successfully completed the
development
of 20+ Python programs based on the curriculum for Class 12 Computer Science and Informatics
Practices.
The programs have been created to demonstrate proficiency in various programming concepts.
Acknowledgement
I would like to express my sincere gratitude to my teachers and mentors who guided me throughout
the process of learning Python programming. Their support and encouragement were instrumental
Special thanks to my classmates and family members for their constant motivation.
Program 1: Prime Number Check
def is_prime(n):
if n <= 1:
return False
if n % i == 0:
return False
return True
print(is_prime(29))
def fibonacci(n):
fib_series = [0, 1]
fib_series.append(fib_series[-1] + fib_series[-2])
return fib_series
print(fibonacci(10))
def sum_of_digits(n):
if n == 0:
return 0
print(sum_of_digits(1234))
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)
print(factorial(5))
if operation == '+':
return a + b
return a - b
return a * b
return a / b
print(calculator(10, 5, '+'))
def count_vowels_consonants(string):
vowels = "aeiouAEIOU"
c_count = len([char for char in string if char.isalpha() and char not in vowels])
print(count_vowels_consonants("Hello World"))
def reverse_string(s):
return s[::-1]
print(reverse_string("hello"))
Program 8: Palindrome Checker
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome("radar"))
def sort_list(lst):
return sorted(lst)
print(sort_list([4, 3, 1, 2]))
def remove_duplicates(lst):
return list(set(lst))
print(remove_duplicates([1, 2, 2, 3, 4, 4, 5]))
def frequency_counter(lst):
return Counter(lst)
print(frequency_counter([1, 2, 2, 3, 4, 4, 5]))
def read_write_file():
data = infile.read()
outfile.write(data)
lines = file.readlines()
class Student:
self.name = name
self.age = age
self.grade = grade
class BankAccount:
self.owner = owner
self.balance = balance
self.balance += amount
self.balance -= amount
account1 = BankAccount("Alice", 1000)
account1.deposit(500)
print(account1.balance)
class Stack:
def __init__(self):
self.items = []
self.items.append(item)
def pop(self):
return self.items.pop()
stack = Stack()
stack.push(1)
stack.push(2)
print(stack.pop())
if arr[mid] == target:
return mid
left = mid + 1
else:
right = mid - 1
return -1
import numpy as np
print(array * 2)
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Plot')
plt.show()
import numpy as np
def matrix_multiplication():
result = np.dot(A, B)
return result
print(matrix_multiplication())