PYTHON Lab (21CSL46) Manual 4th Sem Final
PYTHON Lab (21CSL46) Manual 4th Sem Final
21CSL46
Prepared By:
Prof. Prathima M G & Prof. Suma L
PYTHON PROGRAMMING LABORATORY
Course Objectives:
CLO 1: Demonstrate the use of IDLE or PyCharm IDE to create Python Applications.
CLO 2: Using Python programming language to develop programs for solving real-world
problems.
CLO 4: Appraise the need for working with various documents like Excel, PDF, Word and Others.
Prerequisite
Students should be familiarized about Python installation and setting Python environment
Usage of IDLE or IDE like PyCharm should be introduced
Python Installation: https://www.youtube.com/watch?v=Kn1HF3oD19c PyCharm
Installation: https://www.youtube.com/watch?v=SZUNUB6nz3g
Sl. No. PART A – List of problems for which student should develop program and execute in
the Laboratory
1 Aim: Introduce the Python fundamentals, data types, operators, flow control and
exception handling in Python
a) Write a python program to find the best of two test average marks out of three
test’s marks accepted from the user.
b) Develop a Python program to check whether a given number is palindrome or not
and also count the number of occurrences of each digit in the input number.
Datatypes: https://www.youtube.com/watch?v=gCCVsvgR2KU
Operators: https://www.youtube.com/watch?v=v5MR5JnKcZI
Flow Control: https://www.youtube.com/watch?v=PqFKRqpHrjw
For loop: https://www.youtube.com/watch?v=0ZvaDa8eT5s
While loop: https://www.youtube.com/watch?v=HZARImviDxg
Exceptions: https://www.youtube.com/watch?v=6SPDvPK38tw
Aim: Demonstrating creation of functions, passing parameters and return values
2
a) Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which accepts
a value for N (where N >0) as input and pass this value to the function. Display
suitable error message if the condition for input value is not followed.
b) Develop a python program to convert binary to decimal, octal to hexadecimal using
functions.
Functions: https://www.youtube.com/watch?v=BVfCWuca9nw
Arguments: https://www.youtube.com/watch?v=ijXMGpoMkhQ
Return value: https://www.youtube.com/watch?v=nuNXiEDnM44
3 Aim: Demonstration of manipulation of strings using string methods
a) Write a Python program that accepts a sentence and find the number of words, digits,
uppercase letters and lowercase letters.
b) Write a Python program to find the string similarity between two given strings
Sample Output: Sample Output:
Original string: Original string:
Python Exercises Python Exercises
Python Exercises Python Exercise
Similarity between two said strings: Similarity between two said strings: 1.0
0.967741935483871
Strings: https://www.youtube.com/watch?v=lSItwlnF0eU
String functions: https://www.youtube.com/watch?v=9a3CxJyTq00
4 Aim: Discuss different collections like list, tuple and dictionary
a) Write a python program to implement insertion sort and merge sort using lists
b) Write a program to convert roman numbers in to integer values using dictionaries.
Lists: https://www.youtube.com/watch?v=Eaz5e6M8tL4
List methods: https://www.youtube.com/watch?v=8-RDVWGktuI
Tuples: https://www.youtube.com/watch?v=bdS4dHIJGBc
Tuple operations: https://www.youtube.com/watch?v=TItKabcTTQ4
Dictionary: https://www.youtube.com/watch?v=4Q0pW8XBOkc
Dictionary methods:
https://www.youtube.com/watch?v=oLeNHuORpNY
Aim: Demonstration of pattern recognition with and without using regular expressions
5
a) Write a function called isphonenumber () to recognize a pattern 415-555-4242
without using regular expression and also write the code to recognize the same pattern
using regular expression.
b) Develop a python program that could search the text in a file for phone numbers
(+919900889977) and email addresses ([email protected])
a) Write a python program to accept a file name from the user and perform
the following operations
1. Display the first N line of the file
2. Find the frequency of occurrence of the word accepted from the user in
the file
b) Write a python program to create a ZIP file of a particular folder which
contains several files inside it.
Files: https://www.youtube.com/watch?v=vuyb7CxZgbU
https://www.youtube.com/watch?v=FqcjKewJTQ0
a) By using the concept of inheritance write a python program to find the area of triangle,
circle and rectangle.
b) 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.
OOP’s concepts:
https://www.youtube.com/watch?v=qiSCMNBIP2g Inheritance:
https://www.youtube.com/watch?v=Cn7AkDb4pIU
Aim: Demonstration of classes and methods with polymorphism and overriding
8
a) 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.
Overriding: https://www.youtube.com/watch?v=CcTzTuIsoFk
Aim: Demonstration of working with excel spreadsheets and web scraping
Excel: https://www.youtube.com/watch?v=nsKNPHJ9iPc
10 Aim: Demonstration of working with PDF, word and JSON files
c) PDFs: https://www.youtube.com/watch?v=q70xzDG6nls
https://www.youtube.com/watch?v=JhQVD7Y1bsA
d) https://www.youtube.com/watch?v=FcrW-ESdY-A
e) Word files: https://www.youtube.com/watch?v=ZU3cSl51jWE JSON files:
https://www.youtube.com/watch?v=9N6a-VLBa2I
Python (Full Course): https://www.youtube.com/watch?v=_uQrJ0TkZlc
Pedagogy For the above experiments the following pedagogy can be considered. Problem based
learning, Active learning, MOOC, Chalk &Talk
A problem statement for each batch is to be generated in consultation with the co-examiner and student
should develop an algorithm, program and execute the program for the given problem with appropriate
outputs.
Course Outcomes:
CO 1: Demonstrate proficiency in handling of loops and creation of functions.
CO 2: Identify the methods to create and manipulate lists, tuples and dictionaries.
CO 3: Discover the commonly used operations involving regular expressions and file system.
CO 5: Determine the need for scraping websites and working with PDF, JSON and other file formats.
PROGRAM -1
1a) Write a Python program to find the best of two test average marks out of three test marks
accepted by the user.
avgMarks = (m2+m3)/2
avgMarks = (m1+m3)/2
avgMarks = (m1+m2)/2
print("Average of best two test marks out of three test’s marks is", avgMarks);
OUTPUT
Average of best two test marks out of three test’s marks is 46.5
1b) Develop a Python program to check whether a given number is palindrome or not and also
count the number of occurrences of each digit in the input number.
str_val = str(val)
if str_val == str_val[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
for i in range(10):
if str_val.count(str(i)) > 0:
OUTPUT:
Not Palindrome
1 appears 1 times
2 appears 2 times
3 appears 2 times
4 appears 2 times
Palindrome
1 appears 2 times
2 appears 2 times
3 appears 1 times
PROGRAM -2
2a) Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program that accepts a value
for N (where N >0) as input and pass this value to the function. Display a suitable error message
if the condition for input value is not followed.
def fn(n):
if n == 1:
return 0
elif n == 2:
return 1
else:
return fn(n-1) + fn(n-2)
if num > 0:
print("fn(", num, ") = ",fn(num) , sep ="")
else:
print("Error in input")
OUTPUT:
Enter a number : 5
fn(5) = 3
Enter a number : -5
Error in input
2b) Develop a python program to convert binary to decimal, octal to hexadecimal using
functions.
def btod(a,length):
sum=0
for i in range(0,length):
index=int(a.pop())#extracting LSD of binary number
value=index*pow(2,i)
sum=sum+value
return int(sum)
def input_binary():
n=input('enter the binary number\n')
length=len(n)
a=[]
for i in range(0,length):
char=(n[i])#extracting each digit of binary number from first to last
if(char=='0' or char=='1'):
a.append(char)#inserting the digits of binary number into list from first to last*/
else:
print('invalid binary number')
exit(0)
decimal=btod(a,length)
print('the decimal equavalent of binary number '+n+' is',decimal)
def input_octal():
print("Enter the Octal Number: ")
octnum = int(input())
chk = 0
i=0
decnum = 0
while octnum != 0:
rem = octnum % 10
if rem > 7: # checking for the valid octal number
chk = 1
break
decnum = decnum + (rem * (8 ** i)) #converting octal to decimal
i=i+1
octnum = int(octnum / 10)
if chk == 0:
i=0
hexdecnum = []
while decnum != 0:
rem = decnum % 16
if rem < 10:
rem = rem + 48 # to get the ASCII equivalent of a digit
else:
rem = rem + 55 #to get the ASCII equivalent of an alphabet
rem = chr(rem)
hexdecnum.insert(i, rem)
i=i+1
decnum = int(decnum / 16)
else:
print("\nInvalid Input!")
char='Y'
while(char=='Y'):
print('enter the choice 1. binary to decimal','\t','2. octal to hexadecimal','\n')
choice=int(input())
if choice==1:
input_binary()
elif choice==2:
input_octal()
else:
print('enter your choice correctly')
exit(0)
print('Do you want to continue? Press Y else N')
char=input()
if char=='N':
exit(1)
OUTPUT:
enter the choice 1. binary to decimal 2. octal to hexadecimal
1
enter the binary number
10010
the decimal equivalent of binary number 10010 is 18
Do you want to continue? Press Y else N
786
Invalid Input!
Do you want to continue? Press Y else N
Y
def bin_to_dec():
bin=int(input("Enter a binary number : "))
dec=0
i=0
while bin!=0:
dec+=(bin%10)*(2**i)
i+=1
bin//=10
print("Decimal Equivalent is : ",dec)
def oct_to_hex():
oct=int(input("Enter an octal number : "))
dec=0
i=0
while oct!=0:
dec+=(oct%10)*(8**i)
i+=1
oct//=10
hex =""
while dec!=0:
rem=dec%16
if rem<10:
hex+=str(rem)
else:
hex+= chr(ord('A')+rem-10)
dec//=16
hex=hex[::-1]
print("Hexadecimal Equivalent is : ", hex)
3a) Write a Python program that accepts a sentence and find the number of words, digits,
uppercase letters, and lowercase letters.
split_sentence = sentence.split()
print("The result of split() on input sentence is : \n"+str(split_sentence)+"\n")
words = len(split_sentence )
for c in sentence:
if c.isdigit():
digits = digits + 1
elif c.isupper():
upper = upper + 1
elif c.islower():
lower = lower + 1
OUTPUT:
['Rama', 'went', 'to', 'Devaraja', 'market', 'to', 'pick', '2', 'kgs', 'of', 'vegetable']
No of Words: 11
No of Digits: 1
No of Uppercase letters: 2
No of Lowercase letters: 42
3b) Write a Python program to find the string similarity between two given strings.
OUTPUT:
Enter String 1
Python Exercises
Enter String 2
Python Exercises
Similarity between two said strings:
1.0
Enter String 1
Python Exercises
Enter String 2
Python Exercise
Similarity between two said strings: 0.9375
PROGRAM -4
4a) Write a python program to implement insertion sort and merge sort using lists.
import random
def merge_sort(rec):
if len(rec) > 1:
mid = len(rec) // 2
left_half = rec[:mid]
right_half = rec[mid:]
merge_sort(left_half)
merge_sort(right_half)
i=j=k=0
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j= i-1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
print("\nUnsorted List")
print(my_list)
print("Sorting using Insertion Sort")
insertion_sort(my_list)
print(my_list)
my_list = []
for i in range(n):
my_list.append(random.randint(0, 999))
print("\nUnsorted List")
print(my_list)
print("Sorting using Merge Sort")
merge_sort(my_list)
print(my_list)
OUTPUT:
Unsorted List
[79, 910, 988, 291, 117, 139, 914, 295, 935, 485]
[79, 117, 139, 291, 295, 485, 910, 914, 935, 988]
Unsorted List
[927, 778, 404, 369, 176, 836, 85, 675, 40, 987]
[40, 85, 176, 369, 404, 675, 778, 836, 927, 987]
4b) Write a program to convert Roman numbers into integer values using dictionaries.
def roman_to_int(s):
rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
int_val = 0
for i in range(len(s)):
if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:
int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]
else:
int_val += rom_val[s[i]]
return str(int_val)
OUTPUT:
Roman numerals to integers using Dictionaries
5a) Write a function called isphonenumber( ) to recognize a pattern 415-555-4242 without using
regular expression and also write the code to recognize the same pattern using regular
expression.
import re
def isphonenumber(number):
if len(number) != 12:
return False
if number[3] != '-' or number[7] != '-':
return False
for i in range(12):
if i == 3 or i == 7:
continue
if not number[i].isdigit():
return False
return True
#using RegExpr
def isphonenumber_reg(number):
pattern = r"\d{3}-\d{3}-\d{4}"
match = re.fullmatch(pattern, number)
return match is not None
#main function
ph_num=str(input('enter the phone number in ddd-ddd-dddd format to validate'))
print('enter your choice')
print('Press 1.without RegExpression \t 2. using RegExpression')
choice=int(input())
if choice==1:
res=isphonenumber(ph_num)
if res==True:
print('The phone No.'+str(ph_num)+' is valid')
else:
print('The Phone No.' + str(ph_num) + ' is invalid')
elif choice==2:
res = isphonenumber_reg(ph_num)
if res == True:
print('The phone No.' + str(ph_num) + ' is valid')
else:
print('The Phone No.' + str(ph_num) + ' is invalid')
else:
print('enter the correct option')
exit(0)
OUTPUT:
import re
phone_regex = re.compile(r'\+\d{12}')
email_regex = re.compile(r'[A-Za-z0-9._]+@[A-Za-z0-9]+\.[A-Z|a-z]{2,}')
for line in f:
matches = phone_regex.findall(line)
print(match)
matches = email_regex.findall(line)
print(match)
OUTPUT:
+918151894220
+829392938876
+919900889977
[email protected]
PROGRAM -6
6a) Write a python program to accept a file name from the user and perform the following
operations.
2. Find the frequency of occurrence of the word accepted by the user in the file
import os.path
import sys
lineList = infile.readlines()
for i in range(n):
print(i+1, ":", lineList[i])
OUTPUT:
import os
import sys
import pathlib
import zipfile
dirName = input("Enter Directory name that you want to backup : ")
if not os.path.isdir(dirName):
print("Directory", dirName, "doesn't exists")
sys.exit(0)
curDirectory = pathlib.Path(dirName)
number = 1
while True:
zipFilename = os.path.basename(curDirectory) + '_' + str(number) + '.zip'
if not os.path.exists(zipFilename):
break
number = number + 1
print(f'Creating {zipFilename}...')
with zipfile.ZipFile(zipFilename, mode="w") as archive:
for file_path in curDirectory.rglob("*"):
archive.write(file_path, arcname=file_path.relative_to(curDirectory))
if os.path.isfile(zipFilename):
print("Archive", zipFilename, "created successfully")
else:
print("Error in creating zip archive")
OUTPUT:
Enter Directory name that you want to backup : sample_folder_testing
Creating sample_folder_testing_4.zip...
Archive sample_folder_testing_4.zip created successfully
PROGRAM -7
7a) By using the concept of inheritance write a python program to find the area of a triangle,
circle, and rectangle.
import math
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 math.pi * self.radius ** 2
class Rectangle(Shape):
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
while(True):
print('1. Area of Triangle 2. Area of Circle 3. Area of Rectangle',"\n")
choice=int(input('enter your choice'))
if choice==1:
b=int(input('enter base\n'))
h = int(input('enter height\n'))
triangle = Triangle(b, h)
print("Area of triangle:", triangle.area())
elif choice==2:
r=float(input('enter the radius\n'))
circle = Circle(r)
print("Area of circle:", circle.area())
elif choice==3:
b=int(input('enter base\n'))
l = int(input('enter length\n'))
rectangle = Rectangle(b, l)
print("Area of rectangle:", rectangle.area())
else:
print('invalid choice')
exit(0)
OUTPUT:
1. Area of Triangle 2. Area of Circle 3. Area of Rectangle
enter base
enter height
enter base
enter length
Area of rectangle: 35
invalid choice
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 the salary of
employees belonging to a given department.
class Employee:
def __init__(self, name, employee_id, department, salary):
self.name = name
self.employee_id = employee_id
self.department = department
self.salary = salary
OUTPUT:
enter the number of employee detatils required2
enter 0 th employee details
employee name
rahul
employee id
1
employee dept
cs
employee salary
10000
enter 1 th employee details
employee name
saketh
employee id
2
employee dept
is
employee salary
20000
rahul 1 cs 10000
saketh 2 is 20000
8. Write a Python program to find 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
return self.isPali
class PaliInt(PaliStr):
def __init__(self):
self.isPali = False
if val == rev:
self.isPali = True
else:
self.isPali = False
return self.isPali
stObj = PaliStr()
if stObj.chkPalindrome(st):
print("Given string is a Palindrome")
else:
print("Given string is not a Palindrome")
intObj = PaliInt()
if intObj.chkPalindrome(val):
print("Given integer is a Palindrome")
else:
print("Given integer is not a Palindrome")
OUTPUT:
Enter a string : sas
parent
child
#! python3
# downloadXkcd.py - Downloads every single XKCD comic.
import requests, os, bs4
url = 'http://xkcd.com' # starting url
os.makedirs('xkcd2', exist_ok=True) # store comics in ./xkcd
while not url.endswith('#'):
# Download the page.
print('Downloading page %s...' % url)
res = requests.get(url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text,'html.parser')
# Find the URL of the comic image.
comicElem = soup.select('#comic img')
if comicElem == []:
print('Could not find comic image.')
else:
comicUrl = 'http:' + comicElem[0].get('src')
# Download the image.
print('Downloading image %s...' % (comicUrl))
res = requests.get(comicUrl)
res.raise_for_status()
# Save the image to ./xkcd.
imageFile = open(os.path.join('xkcd2', os.path.basename(comicUrl)), 'wb')
for chunk in res.iter_content(100000):
imageFile.write(chunk)
imageFile.close()
# Get the Prev button's url.
prevLink = soup.select('a[rel="prev"]')[0]
url = 'http://xkcd.com' + prevLink.get('href')
print('Done.')
OUTPUT:
Downloading https://imgs.xkcd.com/comics/barrel_cropped_(1).jpg...
Downloading https://imgs.xkcd.com/comics/radians_are_cursed.png...
Downloading https://imgs.xkcd.com/comics/presents_for_biologists.png...
9b) Demonstrate a python program to read the data from the spreadsheet and write the data into
the spreadsheet.
OUTPUT:
Enter state code for finding capital KA
Corresponding capital for code KA is Bengaluru
Enter state code for finding language TS
Corresponding language for code TS is Telugu
PROGRAM -10
10a) Write a Python program to combine select pages from many PDFs.
num = int(input("Enter page number you want combine from multiple documents "))
pdf_writer = PdfWriter()
pdf1_reader = PdfReader(pdf1)
page = pdf1_reader.pages[num - 1]
pdf_writer.add_page(page)
pdf2_reader = PdfReader(pdf2)
page = pdf2_reader.pages[num - 1]
pdf_writer.add_page(page)
OUTPUT:
Initially take any two pdf files and chose first three pages to combine and give the result in an output
file.
10b) Write a Python program to fetch current weather data from the JSON file.
OUTPUT:
VIVA QUESTIONS
What is Python?
1. Python is one of the most widely-used and popular programming languages, was developed by
Guido van Rossum and released first on February 20, 1991.
2. Python is a free and open-source language with a very simple and clean syntax which makes it easy
for developers to learn Python.
3. It supports object-oriented programming and is most commonly used to perform general-purpose
programming.
4. Python is used in several domains like Data Science, Machine Learning, Deep Learning, Artificial
Intelligence, Scientific Computing Scripting, Networking, Game Development Web Development,
Web Scraping, and various other domains, System Scripting, Software Development, Complex
Mathematics.
What are the benefits of using Python language as a tool in the present scenario?
The following are the benefits of using Python language:
Object-Oriented Language, High-Level Language, Dynamically Typed language, Extensive support
Libraries, Presence of third-party modules, Open source and community development, Portable and
Interactive, Portable across Operating systems.
Is Python a compiled language or an interpreted language?
Python is a partially compiled language and partially interpreted language. ‘#’ is used to comment on
everything that comes after on the line.
Difference between a Mutable datatype and an Immutable data type?
Mutable data types can be edited i.e., they can change at runtime. Eg – List, Dictionary, etc.
Immutable data types can not be edited i.e., they can not change at runtime. Eg – String, Tuple, etc.
What is a lambda function?
A lambda function is an anonymous function. This function can have any number of parameters but,
can have just one statement.
Pass means performing no operation or in other words, it is a placeholder in the compound statement,
where there should be a blank left and nothing has to be written there.
PIP is an acronym for Python Installer Package which provides a seamless interface to install
various Python modules. It is a command-line tool that can search for packages over the internet and
install them without any user interaction.
Sample Programs
a=5
b=6
c=7
s = (a + b + c) / 2
#swapping of 2 numbers
temp=p
p=q
q=temp
sum=0
for i in range(0,n+1):
sum=sum+i
avg=sum/n
print("Result of Average",avg)
fact=1
for i in range(1,n+1) :
fact=fact*i
print(fact)
fact=1
i=1
while i<=n :
fact=fact*i
i=i+1
print(fact)
8. WAP to find fibonacci series using Iterative:
n1, n2 = 0, 1
count = 0
if n <= 0:
elif n == 1:
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
next = n1 + n2
n1 = n2
n2 = next
count += 1
def fib(n):
if n <= 1:
return n
else:
return(fib(n-1) + fib(n-2))
nterms = int(input("How many terms? "))
if nterms<= 0:
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(fib(i))
print("n1 is larger")
print("n2 is larger")
else :
print("n3 is larger")
for i in range(1,11) :
print(i)
12. WAP to print first ten programs using while loop.
I=1
while i<=10:
print(i)
i=i+1
age=input()
type(age)
x=int(age)
if x>18 :
print("eligible")
else :
print("not ")
14. WAP to print grades obtained by the students and print the appropriate message.
marks=input()
type(marks)
x=int(marks)
print('distinction')
print("first")
else :
print("fail")
15.WAP to find factorial of given number using for loop.
fact=1
for i in range(1,6) :
fact*=i
print(fact)
fact=1
i=1
n=int(input())
while i<=n:
fact=fact*i
i=i+1
print(fact)
def fact(n) :
fact=1
i=1
while i<=n :
fact*=i
i=i+1
return fact
#print(fact)
n=int(input("enter the number to find factoral of a given number"))
print(fact(n))
def gcd(a,b):
if b==0:
return a
else :
return gcd(b,a%b)
print(gcd(n1,n2))