Assignment 2 Python
Assignment 2 Python
#python program
def printPicnic(itemsDict, leftWidth, rightWidth):
print('PICNIC ITEMS'.center(leftWidth + rightWidth, '-'))
for k, v in itemsDict.items():
print(k.ljust(leftWidth, '.') + str(v).rjust(rightWidth))
2]
#python program
import re
from_addresses = from_regex.findall(text)
print("From addresses:", from_addresses)
Class: A class in Python is a blueprint for creating objects. It defines a set of attributes
and methods that the created objects can use.
#python program
# Define a class named Person
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def display(self):
print(f"Name: {self.name}")
print(f"Age: {self.age}")
4]
class Point:
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
class Rectangle:
def __init__(self, width=100.0, height=200.0, corner=None):
self.width = width
self.height = height
if corner is None:
self.corner = Point() # Default corner at (0.0, 0.0)
else:
self.corner = corner # Custom corner point