L11
L11
I. Addition
II. Subtraction
III. Multiplication
IV. Division
Write a program to import this module and perform these operations on user-provided numbers.
Implement a function to find the majority element in a list. [Do not use any inbuilt function].
import math_operations as m
print(m.Addition(a,b))
print(m.Subtraction(a,b))
print(m.Multiplication(a,b))
print(m.Division(a,b))
def find_majority_element(nums):
candidate = None
count = 0
if count == 0:
candidate = num
if num == candidate:
count += 1
else:
count -= 1
count = 0
if num == candidate:
count += 1
return candidate
else:
nums = [3, 3, 4, 2, 3, 3, 2, 3]
majority_element = find_majority_element(nums)
INPUT – a = 2
b=2
II. rectangle.py containing functions to calculate the area and perimeter of a rectangle.
circle.area(a)
circle.circumference(a)
rectangle.area(l,b)
rectangle.perimeter(l,b)
INPUT –
a=2
l=2
b=2
OUTPUT –
I. Finds the factorial, square root, and greatest common divisor (GCD) of numbers using
import math
sqrt_result = math.sqrt(num_sqrt)
INPUT –
num_factorial = 4
num_sqrt = 4
num_gcd1 = 4
num_gcd2 = 2
OUTPUT –
math_operations/
├── __init__.py
├── basic/
│ ├── addition.py
│ ├── subtraction.py
├── advanced/
├── factorial.py
├── power.py
Write a program to demonstrate importing functions from both basic and advanced sub-
packages.
def main():
a, b = 10, 5
n=5
base, exponent = 2, 3
if __name__ == "__main__":
main()
OUTPUT –
Q5. Create a package student_management with:
Write a main script that provides a menu-driven interface to use the package.
def main():
while True:
print("4. Exit")
if choice == '1':
if update_marks(roll, new_marks):
else:
print("Student Details:")
view_students()
break
else:
if __name__ == "__main__":
main()
OUTPUT –