1. a) Develop a python program to Compute the 5. a) Develop a python program with help of Command 8.
ith help of Command 8. b) Write a python program to check vote eligibility of a person
GCD of two Numbers using for Loop Line Arguments to display the Word Count.
def is_eligible_to_vote(age):
def gcd_for_loop(a, b): import sys return age >= 18
gcd = 1
for i in range(1, min(a, b) + 1): if len(sys.argv) > 1: age = 20
if a % i == 0 and b % i == 0: filename = sys.argv[1] print("Eligible to vote:", is_eligible_to_vote(age))
gcd = i with open(filename, 'r') as file:
return gcd text = file.read() ======================================================
word_count = len(text.split())
a = 48 print("Word count:", word_count) 9. a) Develop a python program to Display Calendar
b = 18
print("GCD using for loop:", gcd_for_loop(a, b)) =========================================== import calendar
============================================ 5. b) Write a python program which performs def display_calendar(year, month):
merge sort. print(calendar.month(year, month))
1. b) Write a python program to find the maximum of a
list of numbers def merge_sort(lst): year = 2024
if len(lst) > 1: month = 6
def find_max(lst): mid = len(lst) // 2 display_calendar(year, month)
max_num = lst[0] left_half = lst[:mid]
for num in lst: right_half = lst[mid:] ======================================================
if num > max_num:
max_num = num merge_sort(left_half) 9. b) Write a python program to find the factorial of a number
return max_num merge_sort(right_half)
def factorial(n):
numbers = [3, 5, 2, 8, 6] i=j=k=0 if n == 0:
print("Maximum number:", find_max(numbers)) return 1
while i < len(left_half) and j < len(right_half): else:
=========================================== if left_half[i] < right_half[j]: return n * factorial(n - 1)
lst[k] = left_half[i]
2. a) Develop a python program to perform linear search i += 1 number = 5
in a list else: print("Factorial:", factorial(number))
lst[k] = right_half[j]
def linear_search(lst, x): j += 1 ======================================================
for i in range(len(lst)): k += 1
if lst[i] == x: 10. a) Develop a python program to convert kilometre to miles
return i while i < len(left_half):
return -1 lst[k] = left_half[i] def km_to_miles(km):
i += 1 return km * 0.621371
numbers = [3, 5, 2, 8, 6] k += 1
x=8 kilometres = 5
print("Element found at index:", linear_search(numbers, x)) while j < len(right_half): print("Miles:", km_to_miles(kilometres))
lst[k] = right_half[j]
============================================= j += 1 ======================================================
k += 1
2. b) Write a python program find square root 10. b) Write a python program to find the area of a triangle
using newton’s method numbers = [38, 27, 43, 3, 9, 82, 10]
merge_sort(numbers) def triangle_area(base, height):
def newton_sqrt(n, tolerance=1e-10): print("Sorted list:", numbers) return 0.5 * base * height
guess = n / 2.0
while True: =========================================== base = 10
new_guess = (guess + n / guess) / 2 height = 5
if abs(new_guess - guess) < tolerance: 6. a) Develop a python program to program which print("Area of triangle:", triangle_area(base, height))
return new_guess performs insertion sort.
guess = new_guess ======================================================
def insertion_sort(lst):
number = 16 for i in range(1, len(lst)): 11. a) Develop a python program to print the fibbonacci series
print("Square root:", newton_sqrt(number)) key = lst[i]
j=i-1 def fibonacci(n):
===================================== while j >= 0 and key < lst[j]: fib_series = [0, 1]
lst[j + 1] = lst[j] for i in range(2, n):
3. a) Develop a python program to Compute the j -= 1 fib_series.append(fib_series[-1] + fib_series[-2])
GCD of two Numbers using functions lst[j + 1] = key return fib_series[:n]
def gcd(a, b): numbers = [12, 11, 13, 5, 6] n = 10
while b: insertion_sort(numbers) print("Fibonacci series:", fibonacci(n))
a, b = b, a % b print("Sorted list:", numbers)
return a ======================================================
==============================================
a = 48 11. b) Write a python program to find the factorial of a number
b = 18 6. b) Write a python program to Check if a Number is
print("GCD using function:", gcd(a, b)) Odd or Even def factorial(n):
if n == 0:
========================================= def is_even_or_odd(num): return 1
if num % 2 == 0: else:
3. b) Write a python program find the exponentiation return "Even" return n * factorial(n - 1)
of a number else:
return "Odd" number = 5
def exponentiation(base, exp): print("Factorial:", factorial(number))
return base ** exp number = 7
print("The number is:", is_even_or_odd(number)) ======================================================
base = 2
exp = 3 =============================================== 12. a) Develop a python program to find the arm strong number
print("Exponentiation:", exponentiation(base, exp)) 7. a) Develop a python program to Program that takes the
most frequent words in a text file. def is_armstrong(num):
========================================== num_str = str(num)
from collections import Counter num_len = len(num_str)
4. a) Develop a python program to to display the first total = sum(int(digit) ** num_len for digit in num_str)
n prime numbers until the range n is given. def most_frequent_words(filename, n=10): return total == num
with open(filename, 'r') as file:
def is_prime(num): text = file.read() number = 153
if num < 2: words = text.split() print(f"The number {number} is an Armstrong number:", is_armstrong(number))
return False word_counts = Counter(words)
for i in range(2, int(num**0.5) + 1): return word_counts.most_common(n) ======================================================
if num % i == 0:
return False filename = "text.txt" 12. b) Write a python program to find the area of a rectangle
return True print("Most frequent words:", most_frequent_words(filename))
def rectangle_area(length, width):
def first_n_primes(n): =============================================== return length * width
primes = [] 7. b) Write a python program to Display the multiplication
num = 2 Table length = 5
while len(primes) < n: width = 3
if is_prime(num): def multiplication_table(n): print("Area of rectangle:", rectangle_area(length, width))
primes.append(num) for i in range(1, 11):
num += 1 print(f"{n} x {i} = {n*i}") ======================================================
return primes
number = 5
n = 10 multiplication_table(number)
print("First n prime numbers:", first_n_primes(n))
==============================================
============================================
4. b) Write a python program to display the Product of
8. a) Develop a python program to Check whether the given
year is Leap Year or not BIT ADICHU MATTUNA
Two Matrices def is_leap_year(year):
if year % 4 == 0:
COMPANY PORUPPU
def matrix_product(A, B): if year % 100 == 0:
result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))] if year % 400 == 0:
for i in range(len(A)): return True
for j in range(len(B[0])): else:
for k in range(len(B)): return False
result[i][j] += A[i][k] * B[k][j] else:
return result
A = [[1, 2], [3, 4]]
else:
return True
return False
YETRU KOLLATHU
B = [[5, 6], [7, 8]]
print("Product of matrices:", matrix_product(A, B)) year = 2024
print(f"The year {year} is a leap year:", is_leap_year(year))
==============================================