Python Programming Lab
Python Programming Lab
POSTGRADUATION
CENTRE ,KALABURAGI
BACHELOR OF TECHNOLOGY(B.Tech)
IN
ELECTRONICS AND COMPUTER ENGINEERING
A
Report on
PYTHON PROGRAMMING
LABORATORY ( BUEL305 )
USN :
2023 - 2024
VISVESVARAYA TECHNOLOGICAL UNIVERSITY,
BELAGAVICPGS KALABURAGI
CERTIFICATE
Examiners:
OUTPUT :
import math
print("the gcd of 60 and 48 is:",end="")
print(math.gcd(60,48))
OUTPUT :-
def fibonaci(n):
if n==0:
return 0
elif n==1:
return 1
else:
return fibonaci(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("the decimal value of ",dec,"is:")
print(bin(dec),"in binary.")
print(oct(dec),"in octal.")
print(hex(dec),"in hexadecimal.")
OUTPUT :
A
BC
DEF
GHIJ
KLMNO
def contalpha(n):
num=65
for i in range(0,n):
for j in 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 senstence and find the
number of words, digits, uppercase letters and lowercase letters.
s=input("enter a sentence:")
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 of words:",w)
print("no of digits:",d)
print("no of uppercase letters:",u)
print("no of lowercase letters:",l)
OUTPUT :-
n1=15
n2=30
n1=input("enter the value of x:")
n2=input("enter the value of y:")
temp=n1
n1=n2
n2=temp
print("the value of x after swapping:{}".format(n1))
print("the value of y after swapping:{}".format(n2))
OUTPUT :-
class py_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=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]]
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. Write a python program to extract year, month and date from the
URL.
import re
def extract_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 :
import zipfile
import os
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 :
class employee:
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("enter emp salary: "))
def showEmpDetails(self):
print("employee details")
print("name:",self.name)
print("empID:",self.name)
print("dept:",self.dept)
print("salary:",self.salary)
def updtsalary(self):
self.salary=int(input("enter the new salary:"))
print("updated salary:",self.salary)
e1=employee()
e1.getEmpDetails()
e1.showEmpDetails()
e1.updtsalary()
OUTPUT :
wb = Workbook()
ws = wb.active
ws['A1'] = 'Hello'
ws['B1'] = 'World'
wb.save('example.xlsx')
wb = load_workbook('example.xlsx')
ws = wb.active
print(ws['A1'].value)
print(ws['B1'].value)
OUTPUT :
Hello
World
2) Develop a python program to combine selected pages from many
PDFs.
OUTPUT:
import pyqrcode
from pyqrcode import QRCode
dest='www.google.com'
myQR=QRCode(dest)
myQR.show()
OUTPUT :-
4) Create a Quiz game using Python.
else:
print('Incorrect!')
print(f'current answer is --> power supply unit')
question_no += 1
ques = input(f'\n{question_no}. what does ROM stand for? ').lower()
else:
print('Incorrect!')
print(f'current answer is --> read only memory')
else:
print('thankyou you are out of a game.')
quit()
number of question is 5
your score is 3
60.0% questions are correct.