0% found this document useful (0 votes)
35 views17 pages

Aids Python Lab Manual

This document is a laboratory report for an Introduction to Python Programming course at Visvesvaraya Technological University. It includes various Python programming exercises, such as counting digit occurrences, computing GCD, generating Fibonacci sequences, and working with file operations. The report serves as an academic requirement for the second semester of a Bachelor of Technology in Artificial Intelligence and Data Science.

Uploaded by

ashwini.ssangam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views17 pages

Aids Python Lab Manual

This document is a laboratory report for an Introduction to Python Programming course at Visvesvaraya Technological University. It includes various Python programming exercises, such as counting digit occurrences, computing GCD, generating Fibonacci sequences, and working with file operations. The report serves as an academic requirement for the second semester of a Bachelor of Technology in Artificial Intelligence and Data Science.

Uploaded by

ashwini.ssangam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

VISVESVARAYATECHNOLOGICALUNIVERSITY,

BELAGAVI
Center for PG Sutdies, Kalaburagi
Bachelor of Technology(B.Tech)
In
ARTIFICIAL INTELLIGENCE AND DATASCIENCE

A
Laboratory
Report on
INTRODUCTION TO PYTHON PROGRAMMING
LABORATORY
( BPLCK205B )

Submitted as a part of Academic Requirement for Second Semester


By

(USN: )

Department of Computer Science and Engineering,


Centre for PG Studies, Visvesvaraya Technological University,
Kalaburagi 585105

2024–2025
USN: DATE:24 /06/2025

CERTIFICATE

This is to certify that Mr./Ms.…………………………………………..


Studying in the Department of CSE Second Semester has successfully completed
all the Programs in……………………………with subject as prescribed by the
Visvesvaraya Technological University, Belagavi CPGS Kalaburagi for
the academic year 2024-2025.

Faculty In charge Program Coordinator

Examiners:

1.Internal Examiner 2.Internal Examiner


1) a. Develop a python program to count the number of occurrences of each
digit in the given input number.

n=int(input("enteranyintegervalue:"))
n=str(n)
m=input("enterthenumberofcount:")
print("count is:",n.count(m))

OUTPUT:

enteranyintegervalue:123445322
enter the number of count:2 count
is: 3
b. Write a python program tocompute the GCD of two numbers.

importmath
print("thegcdof60and48is:",end="")
print(math.gcd(60,48))

OUTPUT:-

thegcdof60and48 is:12
2) a. Write a python program to print theFibonaccisequence.

deffibonaci(n):
ifn==0:
return0
elif n==1:
return 1
else:
returnfibonaci(n-1)+fibonaci(n-2)
for i in range(5):
print(fibonaci(i))

OUTPUT:

0
1
1
2
3
b. Develop a python program to convert a given decimal number to
Binary, Octal and Hexadecimal using functions.

dec=60
print("thedecimalvalueof",dec,"is:")
print(bin(dec),"in binary.")
print(oct(dec),"in octal.")
print(hex(dec),"in hexadecimal.")

OUTPUT:

thedecimalvalueof60is:
0b111100 in binary.
0o74in octal.
0x3c in hexadecimal.
3)a. Develop a python program to print the following pattern.

AB
C
DEF
GHIJKL M
NO

def contalpha(n):
num=65foriin
range(0,n):
forjin range(0,i+1):
ch=chr(num)
print(ch,end="")
num=num+1
print("\r")
n=5
contalpha(n)

OUTPUT:-

BC

DEF

GHIJ

KLMNO
b. Write a python program that accepts a senstenceand find the numberof
words, digits, uppercase letters and lowercase letters.

s=input("enterasentence:")
w,d,u,l=0,0,0,0 lw=s.split()
w=len(lw) for c in s: if
c.isdigit(): d=d+1 elif
c.isupper(): u=u+1 elif
c.islower():
l=l+1
print("no ofwords:",w) print("no
of digits:",d) print("no of
uppercaseletters:",u)print("noof
lowercase letters:",l)

OUTPUT:-

enterasentence:YUKTI2024wasgreatestfunctioninvtu
noofwords: 7 noofdigits: 4noofuppercaseletters: 5 no of
lowercase letters: 24
4) a. Write a python program to swap two elements in a list.

n1=15
n2=30
n1=input("enterthevalueofx:")
n2=input("enterthevalueofy:")
temp=n1
n1=n2
n2=temp
print("thevalueofxafter swapping:{}".format(n1))
print("thevalueofyafterswapping:{}".format(n2))

OUTPUT:-

enterthevalueofx:15enterthe
value of y:30 the value of x
after swapping:30 the value of
y after swapping:15
b. Write a program to convert roman numbers into integer values
using dictionaries.

classpy_solution:
def roman_to_int(self,s):
rom_val={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
int_val=0foriin 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]]
else:
int_val+=rom_val[s[i]]
return int_val
print(py_solution().roman_to_int('MMMMLXXXVI'))
print(py_solution().roman_to_int('MMMD'))
print(py_solution().roman_to_int('C'))

OUTPUT:

4086
3500
100
5) a. Develop a python program that could search the text in a file for
phone numbers (+919900889977) and email addressess (
[email protected] ).

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,}')
with open('b.txt','r')as f:
for line in f:
matches=phone_regex.findall(line)
for match in matches:
print(match)
matches=email_regex.findall(line)
for match in matches:
print(match)

OUTPUT:

+919900889977
[email protected]
b.Writeapythonprogramtoextractyear,monthanddatefromtheURL.

importre
defextract_date(url):
return
re.findall(r'/(\d{4})/(\d{1,2})/(\d{1,2})/',url)
urll="www.vtu.ac.in/2020/02/22/"
print(extract_date(urll))

OUTPUT:

[('2020','02','22')]
6) Write a python program to create a ZIP file of a particular folder
which contains several files inside it.

importzipfile
import os

defzip_folder(folder_path,zip_filename):
withzipfile.ZipFile(zip_filename,'w')aszip_file:
forfoldername,subfolders,filenamesinos.walk(folder_path): for
filename in filenames: file_path =
os.path.join(foldername,filename)arcname=
os.path.relpath(file_path, folder_path)
zip_file.write(file_path, arcname)

folder_to_zip="/path/to/your/folder"
zip_file_name = "output.zip"

zip_folder(folder_to_zip,zip_file_name)print(f"Zip file
'{zip_file_name}' created successfully.")

OUTPUT:

Zipfile'output.zip'createdsuccessfully.
7) 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.

classemployee:
def _init_(self):
self.name=""
self.empID=""
self.dept=""
self.salary=0
def getEmpDetails(self):
self.name=input("enter emp name: ")
self.empID=input("enter emp empID: ")
self.dept=input("enter emp dept: ")
self.salary=int(input("enterempsalary:"))
def showEmpDetails(self):
print("employee details")
print("name:",self.name)
print("empID:",self.name)
print("dept:",self.dept)
print("salary:",self.salary)
defupdtsalary(self):
self.salary=int(input("enterthenewsalary:"))
print("updated salary:",self.salary)
e1=employee()
e1.getEmpDetails()
e1.showEmpDetails()
e1.updtsalary()
OUTPUT:

enterempname:admin
enterempempID:ADMIN22EE001
enter emp dept: engineering enter
emp salary: 100000 employee
details name: admin empID: admin
dept: engineering salary:
100000 enter the new
salary:200000updated
salary: 200000
8) 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.
classA:
def init
(self,s):
self.s = s

defpalindrome(sel
f): rev =
self.s[::-1]
if rev == self.s:
print("Thestringisa
palindrome")
else:
print("Thestringisnota
palindrome")

classB(A):
def init (self, s):
super(). init
(s)

defpalindrome(sel
f): temp =
self.s
rev=0
while self.s != 0:
dig=self.s%10
rev=rev*10+dig
self.s = self.s // 10
if temp ==
rev:print("Thenum
berisa
palindrome")
else:
print("Thenumberisn'ta
palindrome")

string_input=input("Enterthestring:")
integer_input=int(input("Enterthe
integer:"))
a=A(string_input)
b=B(integer_input)
a.palindrome()
b.palindrome()

OUTPUT: Enterthestring: MADAM


Enter the integer: 12321
Thestringisapalindrome
Thenumberisapalindrome

You might also like