Python_Programs_Assignment
Python_Programs_Assignment
class Person:
def __init__(self, name):
self.name = name
class Skills:
def __init__(self, skill):
self.skill = skill
def display_info(self):
print(f"Name: {self.name}, Skill: {self.skill}, Employee ID: {self.employee_id}")
if choice == '1':
print("Result:", add(a, b))
elif choice == '2':
print("Result:", subtract(a, b))
elif choice == '3':
print("Result:", multiply(a, b))
elif choice == '4':
print("Result:", divide(a, b))
else:
print("Invalid choice")
try:
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
result = a / b
except ZeroDivisionError:
print("Error: Cannot divide by zero.")
except ValueError:
print("Error: Invalid input. Please enter integers.")
else:
print("Result:", result)
class Faculty:
def __init__(self, name, dept, emp_id):
self.name = name
self.dept = dept
self.emp_id = emp_id
def display(self):
print(f"Name: {self.name}, Department: {self.dept}, ID: {self.emp_id}")
def display(self):
print(f"Name: {self.name}, Department: {self.dept}, ID: {self.emp_id}")
f1 = Faculty()
f1.display()
f2 = Faculty("Dr. Allen", "ECE", "F100")
f2.display()
import tkinter as tk
def show_data():
print(f"Name: {name_entry.get()}, Subscribe: {var.get()}")
root = tk.Tk()
root.title("Simple GUI")
var = tk.BooleanVar()
tk.Checkbutton(root, text="Subscribe to newsletter", variable=var).pack()
import re
phone_pattern = r"^\+?\d{10,13}$"
email_pattern = r"^[\w\.-]+@[\w\.-]+\.\w+$"
if re.match(phone_pattern, phone):
print("Valid phone number")
else:
print("Invalid phone number")
if re.match(email_pattern, email):
print("Valid email ID")
else:
print("Invalid email ID")
13. Numpy 1D, 2D, 3D Arrays + Operations
import numpy as np
a = np.array([1, 2, 3]) # 1D
b = np.array([[1, 2], [3, 4]]) # 2D
c = np.array([[[1], [2]], [[3], [4]]]) # 3D
print("1D:", a)
print("2D:", b)
print("3D:", c)
# Reshape
reshaped = b.reshape(1, 4)
print("Reshaped 2D to 1x4:", reshaped)
import numpy as np