6-10 Python Lab Program
6-10 Python Lab Program
OUTPUT:
Enter N value: 3
The following are the first 3 lines of a text file:
Welcome To Python Programming
Studying in computer science branch at JIT
Import the regex module with import re.
Enter word to be searched: JIT
Occurrences of the word JIT is: 1
Zip File Creation
6.b) Write a python program to create a ZIP file of a particular folder which contains
several files inside it.
import os
from zipfile import ZipFile
if os.path.exists('E:/Zipped file.zip'):
print("ZIP file created")
else:
print("ZIP file not created")
OUTPUT:
PROGRAM 7
Aim: Demonstration of the concepts of classes, methods, objects and inheritance
Inheritance
7a. By using the concept of inheritance write a python program to find the area of
triangle, circle and rectangle.
class Shape:
def area(self):
pass
class Triangle(Shape):
def __init__ (self, base, height):
self.base = base
self.height = height
def area(self):
return 0.5 * self.base * self.height
class Circle(Shape):
def __init__ (self, radius):
self.radius = radius
def area(self):
return 3.14 * self.radius * self.radius
class Rectangle(Shape):
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
b=int(input("Enter the value of base"))
h=int(input("Enter the value of height"))
triangle = Triangle(b,h)
print("Area of the Triangle:", triangle.area())
r=int(input("Enter the value of radius"))
circle = Circle(r)
print ("Area of the Circle:", circle.area())
OUTPUT:
Enter the value of base5
Enter the value of height6
Area of the Triangle: 15.0
Enter the value of radius5
Area of the Circle: 78.5
Enter the value of Length6
Enter the value of width7
Area of the Rectangle: 42
Employee Details
7b)Write a python program by creating a class called Employee to store the details of Name,
Employee_ID, Department and Salary, and implement a method to update salary of
employees belonging to a given department.
class Employee:
def __init__(self):
self.name = ""
self.empId = ""
self.dept = ""
self.salary = 0
def getEmpDetails(self):
self.name = input("Enter Employee name : ")
self.empId = input("Enter Employee ID : ")
self.dept = input("Enter Employee Dept : ")
self.salary = int(input("Enter Employee Salary : "))
def showEmpDetails(self):
print("Employee Details")
print("Name : ", self.name)
print("ID : ", self.empId)
print("Dept : ", self.dept)
print("Salary : ", self.salary)
def updateSalary(self):
self.salary = int(input("Enter new Salary : "))
print("Updated Salary", self.salary)
e1 = Employee()
e1.getEmpDetails()
e1.showEmpDetails()
e1.updateSalary()
OUTPUT:
Enter Employee name : RAM
Enter Employee ID : 1607
Enter Employee Dept : CSE
Enter Employee Salary : 45000
Employee Details
Name : RAM
ID : 1607
Dept : CSE
Salary : 45000
Enter new Salary : 50000
Updated Salary 50000
Program 8
Aim: Demonstration of classes and methods with polymorphism and overriding
polymorphism and overriding
Write a python program to find the whether the given input is palindrome or not
(for both string and integer) using the concept of polymorphism and inheritance.
class PaliStr:
def __init__(self):
self.isPali = False
if myStr == myStr[::-1]:
self.isPali = True
else:
self.isPali = False
return self.isPali
class PaliInt(PaliStr):
def __init__(self):
self.isPali = False
temp = val
rev = 0
while temp != 0:
dig = temp % 10
if val == rev:
self.isPali = True
else:
self.isPali = False
return self.isPali
stObj = PaliStr()
if stObj.chkPalindrome(st):
else:
intObj = PaliInt()
if intObj.chkPalindrome(val):
else:
import requests
import os
from bs4 import BeautifulSoup
OUTPUT:
Current temperature: 15.45°C
Humidity: 64%
Weather description: clear sky