We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 21
‘wraor2020 Diruvikan pynb -Colaboratory
1)
Write a function to create a text file containing following data:
Neither apple nor pine are in pineapple. Boxing rings are square.
Writers write, but fingers don’t fing. Overlook and oversee are opposites.
A house can burn up as it burns down. An alarm goes off by going on.
a) Read back the entire file content using read( ) or readlines( ) and display on the
screen.
b) Append more text of your choice in the file and display the content of file with
Line numbers prefixed to line.
c) Display last line of file.
d) Display first line from 1@th character onwards.
e) Read and display a line from the file. Ask user to provide the line number to be
read.
f) Find the frequency of words beginning with every letter i.e.
(for the above example)
Words beginning with a:
Words beginning with n:
Words beginning with p:
Words beginning with o:
and so on
# Part a) start
def function()
open('Praci', 'w')
k.writelines("Neither apple or pine are in pineapple. Boxing rings are square. \nWriters
pen( ‘Praci")
-read()
print(r)
function()
# Part a) finished
Neither apple or pine are in pineapple. Boxing rings are square.
Writers write, but fingers don't fing. Overlook and oversee are opposites.
house can burn up as it burns down. An alarm goes off by going on.
# Part b) start
k=open('Praci','a')
k.write(‘\nSticks and stones may break your bones.")
k=open( Pract")
r=k.readlines()
for a in range(len(r)):
print(a+1,r[a])
# Part b) finished
1 Neither apple or pine are in pineapple. Boxing rings are square.
2 Writers write, but fingers don't fing. Overlook and oversee are opposites.
3 A house can burn up as it burns down. An alarm goes off by going on.
4 Sticks and stones may break your bones.
# Part c) start
hitps:ieolab research google comvrivelhiOmuECqBu2q4y4L.N38319h_WUCz0UZ7usp=sharingtscroT
22‘9012020 DDhruvckan jpynb-Colaboratory
pent vract , my
-readlines()
print (r[1en(r)-1])
# Part c) finished
Sticks and stones may break your bones.
# Part d) start
keopen( Pract", 'r')
k.seek(10)
-readline()
print(r)
# Part d) finished
ple or pine are in pineapple. Boxing rings are square.
# Part e) start
def read(1):
sopen('Pracl','n')
-Peadlines()
print(r(1])
nt(input("Enter the line num: '))
read(1-1)
# Part e) finished
Enter the line num: 2
Writers write, but fingers don't fing. Overlook and oversee are opposites.
# Part f) start
pen( "Pract", 'r')
-read()
+
for a in r:
d{a]=0
for a in r:
d[a}e=2
print(d)
# Part #) finished
2)
Assume that a text file naned Filet.txt contains some text, weite a function naned
isvonel( ) that reads the file filei.txt and creates a new File naned file2.txt, which sha
contain only those words from the file filel.txt which don’t start with a vowel
For example, if the filet.txt contains:
Carry Unbrella and Overcoat When it Rains
Then the file file2.txt shall contain
Carry When Rains
hitps:icolab research google convrivel hiOmujECqBu2q6y4L.N38319h_WUCz0UZ7usp=sharingtscroITo“
2122‘wraor2020 Diruvkkan pynb -Colaboratory
aropen('Filel.txt', 'w')
a.write('do not Carry Umbrella and Overcoat When it does not Rain’)
a.close()
def isvovel(a):
pen('File2.txt', ‘w")
vovellst=[65,69,73,79,85,97,101,105,111,117]
wea.read()
-split()
for y in
if ord(y[@]) in vovelist:
pass
else:
b.write(y+"
b.close()
beopen('File2.txt', 'r")
c=b.read()
print(‘Contents of filet: do not Carry Umbrella and Overcoat When it does not Rain’)
print(‘Contents of file2:',c)
azopen('filel.txt', 'r')
xeisvovel(a)
Contents of filel: do not Carry Umbrella and Overcoat When it does not Rain
Contents of file2: do not Carry When does not Rain
3)
A file containing data about a collection of students has the following format.
Rajat Sen 12345 1 CSEE
Jagat Narain 13467 3 CSEE
Anu Sharma 11756 2 Biology
SumitaTrikha 23451 4 Biology
Sumderkumra 11234 3 MME
KantiBhushan 23211 3 CSEE
Each line contains a first name, a last name, a registration number, no of years and a
department separated by tabs.
a) lirite a Python progran that will copy the contents of the file into a list of tuples
b) Display:
1) The full details of the student sorted by registration number
2) The names of all students with no of year less than 3
3) The number of people in each department
pen( ‘tuplewriter.txt', 'w')
op.writelines("Rajat Sen 12345 1 CSEE \nJagat Narain 13467 3 CSEE \nAnu Sharma 11756 2 Bio
op.close()
# Part a) start
pen( 'tuplewriter.txt','r')
arop.readlines()
Ast append(tuple(q))
print(‘List of tuples is:*,1st)
Ist. sort (key=reg_no)
hitpsiicolab research google convrivel hiOmuyECqBu2q4y4l. h38319h_WUCzZ0UZ7usp=sharingHscrol
3122‘wraor2020
# Part a) finished
List of tuples is: [(‘Rajat', ‘Sen’, 12345",
# Part b) 1) start
infolist=[‘First Name’, ’Last Name’,’ Reg. no.","
op=open(‘tuplewriter.txt', 'r')
rd=op.read()
def reg_no(element)
return element[2]
for k in range(len(infolist))
print(infolist[k],end=' ')
Ist. sort (key=reg_no)
for k in range(len(infolist)+1):
pelst[k]
print()
for x in range(len(p)):
print(p[x],end="\t\t" )
# Part b) 1) finished
First Name Last Name Reg. no.
Sunder kumra 11234
Anu Sharma 11756
Rajat Sen 12345
Jagat Narain 13467
kanti Bhushan 23211
Sumita Trikha 23451
# Part b) 2) start
op=open(‘tuplewriter.txt', ‘r*)
rd=op.read()
infolist=[ ‘First Name’, ‘Last Name", "Year" ]
def yearsort (element):
return element[3]
for k in range(len(infolist)):
print (infolist[k],end="\t')
Ist. sort (key=yearsort) , print()
for x in Ist:
for k in range(len(infolist)+1):
p=x(k]
if ord(x[3])<52
if kl=2:
w.append(x{k])
for a in range(len(w)):
if ace;
print(wla],end="\t\t *)
print()
for a in range(len(w)):
if a=:
print(w[a],end="\t\t ')
# Part b) 2) finished
hitps:icolab research google comvrivel hiOmujECqBu2q6y4L.N38319h_WUCz0UZ7usp=sharingtscroITo“
Diruvkkan pynb -Colaboratory
» ‘CSEE'), (‘Jagat', ‘Narain’, '134¢
>
Year',' Dept."]
Year Dept.
3 MME
Biology
cSEE
CSE
CSEE
Biology
RuuEN
4122‘wraor2020 Diruvkkan pynb -Colaboratory
First Name Last Name Year
Rajat Sen 1
Anu Sharma 2
# Part b) 3) start
op-open(‘tuplewriter.txt', 'r')
Ast, a,deptdict=[],[],{}
rd-op.read()
deptlst=[‘MME', ‘CSEE" , ‘Biology’ ]
for i in rd:
asrd.split()
try:
for x in range(len(a)):
Ist -append(a[4+5*x])
except Indexerror:
pass
for x in Ist:
deptdict[x]=0
for x in Ist:
deptdict[x]+=1
for x in deptist:
print(“The number of people in “+x+" department are:
# Part b) 3) finished
sdeptdict[x])
‘The number of people in MME department are: 1
‘The nunber of people in CSEE department are: 3
The number of people in Biology department are:
4)
Write is a program that reads a file“myfile.txt” and builds a histogram (a dictionary
as {word:occurrence}) of the words in the file.
a) Now use histogram to print
i) Total number of words
ii) Number of different words
iii) The most common words
b) Using above text file “nyfile.txt”, write a program that maps a list of words read
from the file to an integer representing the length of the corresponding words.( use
dictionary having key value pair as length : list of word )
Now using above dictionary design a function find_longest_word() to display a list of
longest words from file.
Define a function filter_long_words(n) that takes an integer n and returns the list of
words that are longer than n from file.
op=open(‘myfile.txt", 'w')
op.writelines("Neither apple or pine are in pineapple. Boxing rings are square. \nwriters w
op.close()
dict=(}
op=open(‘myfile.txt','r')
rd=op.read()
# Part a) start
Ist-rd. split()
for word in Ist:
dict[word]-0
hitps:icolab research google convrivel hiOmujECqBu2q6y4L.N38319h_WUCz0UZ7usp=sharingtscroITo“
5122‘wvs0/2020 Dhnuvkikan.pynt - Colaboratry
tor word in Ist:
dict[word]+=1
no=8
wordIst=[]
for k in dict:
not=dict[k]
lower=@
for k in dict:
if dict[k]>lower:
lower=dict[k]
xek
print('Number of words is: ',no)
print('Number of different words is :',dict)
print(‘The most common word is: “'+x+'" and it occurs’, lower, times. ")
# Part a) finished
Number of words is: 38
Number of different words is : {‘Neither': 1, ‘apple’: 1,
The most common word is: “are” and it occurs 3 times.
< >
# Part b) start
# create a dictionary having key as length of word and value as a list conting the word
op-open(‘myfile.txt’,‘r')
rd=op.read()
wordIst=rd.split()
d={}
for word in wordlist
d{len(word) ]=[]
for word in wordlist
d[1en(word) ].append(word)
def find_longest_word(dict):
lowest
for a in dict:
if a>lowest:
lowest=a
print(‘List of longest words in file is:',dict[lowest])
find_longest_word(d)
def filter_longer_words (num, dict) :
for a in dict:
if asnum:
print(‘Words with length longer than‘ ,num,"is: ',dict[a], ‘and their length is :
nt(input("Enter a number: '))
filter_longer_words(n,d)
# Part b) finished
2a)
List of longest words in file is: [‘pineapple.', ‘opposites."]
Enter a number: 7
Words with length longer than 7 is: [‘pineapple.', ‘opposites.'] and their length is
Words with length longer than 7 is: [‘Overlook'] and their length is : 8
< >
5)
A dictionarv Customer contains the following kevs froomno.name.duration>
hitps:icolab research. gongle.comcrivel hiOmufECqBu2qdyél. h38319h_WUC20UZ7uspsharingHscrolTorkézihz7 JKMow 22‘wreor2020 Diruvikan ipynb -Colaboratory
A binary file “hotel.dat” contains details of customer checked in the hotel.
Write a code in python to perform the following using pickle module
i)Read n dictionary objects and load them into the file
ii)Read all the dictionary objects from the file and print them
iii)Counts the number of customers present in the hotel.
iv)Display those customers from the file, who have stayed more than 2 days in the hotel.
infolst=[{ ‘Name’: ‘John’, ‘RoomNo' :56, ‘Duration’ :1.5},{'Name' : ‘Jack' , 'RoomNo' :42, ‘Duration’
import pickle
op=open(‘Hotel.dat", "wo")
pickle. dunp(infolst, op)
op.close()
op=open( ‘Hotel. dat’, "rb')
lo=pickle.10a¢(op)
nun=int(input('Please enter a number:
# Part i) start
try:
if num:
)
en(1o):
for a in range(num):
print (1o[a])
else:
print(‘Please enter a lower nunber')
except IndexError:
pass
# Part i) finished
Please enter a number: 2
{Nane": "John*, 'RoonNo
{'Nane*: "Jack", ‘RoonNo
56, ‘Duration
: 42, ‘Duration’:
1.5}
5}
# Part ii) start
for a in lo:
print(a)
# Part ii) finished
{'Nane*
{Nane
(Name
"John", ‘RoomNNo"
"Jack", ‘RoomNo
"3411", ‘RoomNo
56, ‘Duration’
42, ‘Duration
551, ‘Duration
1.5}
5}
9831)
# Part iii) start
for a in range(len(1o)):
continue
print('There are’,a+1, "people in the hotel’)
# Part iii) finished
There are 3 people in the hotel
# Part iv) start
for k in lo:
if k[ ‘Duration’ }>2:
print(‘The customer staying for more than 2 days is',k)
# Part iv) Finished
hitpsiicolab research google convrivel hiOmujECqBu2q4y4l. h38319h_WUCzZ0UZ7usp=sharingtscrolT
7122‘wraor2020 Diruvkkan pynb -Colaboratory
The customer staying for more than 2 days is {'Name’: "Jack", 'RoomNo’: 42, ‘Duratior
The customer staying for more than 2 days is {‘Name': ‘Jill', ‘RoomNo’: 551, ‘Duratic
« >
6)
Sun Microsystems when held recruitment test, the file placement.csv containing the below f
The marks are from 5 different tests conducted and each column is out of 5 marks.
John -4-3-4-2-5
Peter -3-4-4-3-5.
a) Read the above file and print the data
b) Write User Defined Function to find total no of people who came for the placement test
) Winite the UDF to find the top n Names on basis of total Marks
import csv
‘'*func_name=str(input("Enter the name of the function: '))
def func_nane():
rows=['S.no.", Name", “Test 1°, "Test 2°, "Test 3°, "Test 4°, Test 5°]
colunns=[[1, John" ,5,5,5,5,5],[2, ‘Peter’ ,3,3,3,3,3],[3, "Gary’,5,4,5,3,4],[4, ‘Dave’ ,4,4,4,4
with open('placement.csv','w' ,newline="') as a_file:
writer=csv.writer(a_file)
writer.writerow(rows)
uriter.writerows(colunns)
# Part a) start
with open('placement.csv','r') as a_file:
read=csv.reader(a_file)
Lines=list(read)
for x in Lines:
for y in x:
print(y,end="\t")
print()
# Part a) finished
S.no. Name Test 1 Test 2 Test 3 Test 4 Test 5
1 John 5 5 5 5 5
2 Peter 3 3 3 3 3
3 Gary 5 4 5 3 4
4 Dave 4 4 4 4 4
# Part b) start
def b_part():
with open (‘placement.csv') as r_fi
‘sv.reader(r_file)
ist(read)
for x in range(len(1ines)):
continue
print(x)
b_part()
# Part b) finished
4
# Part c) start
nzint(input('Enter the amount of top contestants required: '))
hitpscolab research google comsvel hiOmujECaBu2a4yalh38319h WUCZOUZ?usp=sharinglscral
8122‘wraor2020 Diruvikan pynb -Colaboratory
‘topnanes=[]
marks, d1,d2=[],{},{}
def c_part(n):
with open(‘placement.csv') as r_file:
read=csv.reader(r_file)
lines=list(read)
for x in lines[1:
topnames.. append(x)
for k in lines[1:
marks. append (int (k[2])+int (k[3])+int(k[4])+int(k[5]))
for y in range (1en(marks)):
di [y+ ]=marks[y]
marks. sort(reverse=True)
for y in range(len(marks)):
a2[y+1]=marks[y]
index=1
while indexc=n:
print (d2[index])
index+=1
<_part(n)
# Part c) finished
Enter the amount of top contestants required: 3
20
7
16
7)
Write a program to input a number and then call the functions
a) count(n) which returns the number of digits
b) reverse(n) which returns the reverse of a number
c) hasdigit(n) which returns True if the number has a digit else False
d) show(n) to show the number as sum of place values of the digits of the number
# Part a) start
nput("Enter a Number: ")
def count(n):
print(‘Digits in
count(n)
# Part a) finished
are: ',len(n))
Enter a Number: 2132156
Digits in "n" are: 7
# Part b) start
input("Enter a Number: ")
def reverse(n
print(‘"n
reverse(n)
# Part b) finished
reversed is: ‘,n[-1
Enter a Number: 684615
n” reversed is: 516486
hitps:icolab research google comvrivel hiOmujECqBu2q6y4L.N38319h_WUCz0UZ7usp=sharingtscroITo“
9122‘wraor2020 Diruvkkan pynb -Colaboratory
# Part c) start
neinput(“Enter a Number:
def hasdigit(n):
for x in
falg-False
try:
int (x)
falg=True
break
except:
passas
print(‘"n" has digits: ',falg)
hasdigit(n)
# Part c) finished
Enter a Number: evd54
n” has digits: True
# Part d) start
nput("Enter a Number: ")
def show(n):
print( "Place Value= ',end="")
Ast=[]
for x in n:
Ist append(x)
print(n,end="=")
for x in range(len(1st)):
print (int (1st[x])*1@**(len(1st)=x-1), en
if x!=len(1st)-1:
print (end="+")
show(n)
# Part 4) finished
Enter a Number: 65684
Place Value= 65684=60000+5000+600+80+4
8)
A Number is a perfect number if the sum of all the factors of the number
(including 1) excluding itself is equal to number.
Winite functions
a) GenerateFactors() to populate a list of factors
b) isPrimeNum() to check whether the number is prime number or not
c) isPerfectNum() to check whether the number is perfect number or not
# Part a) start
nun=int(input("Enter a Number: "))
def GenerateFactors (num):
global 1st
Aste[]
for x in range(1,num):
if numix==0:
Ist -append(x)
hitpsicolab research google convrivel hiOmufECqBu2q6y4L.N38319h_WUCz0UZ7usp=sharingtscroITo“
10122‘wraor2020 Diruvkkan pynb -Colaboratory
print(‘Factors:',1st)
GenerateFactors (num)
# Part a finished
Enter a Number: 654
Factors: [1, 2, 3, 6, 109, 218, 327]
# Part b) start
nun=int(input(“Enter a Number: “))
def isPrimeNo(num) :
global 1st
if len(1st!
print("It IS A prime number")
else:
print ("It IS NOT A prime number")
isPrimeNo(num)
# Part b) Finished
Enter a Number: 654
It IS NOT A prime number
# Part c) start
nun=int(input("Enter a Number: “))
def isPerfectNo(num) :
global 1st
sum=@
for x in Ist:
print ("It IS A perfect number")
else:
print ("It IS NOT A perfect number")
isPerfectNo(n)
# Part c) finished
Enter a Number: 654
It TS NOT A perfect number
9)
Pascal’s triangle is a number triangle with numbers arranged in staggered rows such that a
This equation is the equation for a binomial coefficient. Write a recursive function in Py
import math
def tri(i):
n= int(input("Enter Number: "))
for x in range(n)
for y in range(x+1):
itestr(math. factorial (x)//(math. factorial (y)*math. factorial (x-y)))
print (4)
swe‘wraor2020 Diruvkkan pynb -Colaboratory
Enter Number: 6
1
Et
121
1331
14641
15101051
10)
Input number in decimal and desired type
(Specify B for Binary, 0 for Octal, H for Hexadecimal) for output.
# Part a) start
def bin(1st, num):
rem=numi2
Ist. append(rem)
num=num//2
if num
bin(1st num)
else:
Ist reverse()
for x in Ist:
print (x,end=
nun=int(input("Enter decimal number
bin(Ist,num)
# Part a) finished
»
Enter decimal number: 654
1019001110
# Part b) start
Ist=[]
nun=int(input ("Enter decimal number: "))
def oct(1st, num):
rem=nunks
1st -append(rem)
num=num//8
if num!=0:
oct (1st, num)
else:
Ast.reverse()
for x in Ist:
print (x,eni
oct (1st, num)
# Part b) finished
Enter decimal number: 654
1216
# Part c) start
num=int (input ( »
hitpsicolab research. google convcrivel hiOmuECqBu2q4y4l.h38319h_WUCzZ0UZ7usp=sharingtscroT
nter decimal number
12122‘nvs0/2020 Dhnuvkikan.pynt - Colaboratry
det Hex(num):
s
while num!=@:
if numka6>.
st+=chr(55+(num%16) )
else:
stt=str(numti6)
num//=16
print(st[
Hex(num)
# Pact c) finished
1])
Enter decimal number: 654
28E
11)
Write a program to input a list and write the function for the following:
a) To sort list using bubble sort and find efficiency
b) To search an element using linear search and find efficiency
¢) To search an element using binary search and find efficiency
# Part a) start
1
nt(input("Enter the length of required list: '))
for x in range(n):
nt(input('Enter element: *))
L.append(k)
def bubble(1):
flag=0
while flag
flay
for x in range(len(1)-1):
Sf Ipett]el [x]:
8:
flag = 0
e=1[x]
ApxJ=1 [x41]
Ipet]=e
bubble(1)
print(1)
# Part a) finished
Enter the length of required list: 6
Enter elenent: 5
Enter elenent
Enter elenent
Enter elenent:
Enter elenent
Enter elenent:
[1 2.3, 5, 6 8]
# Part b) start
1
nsint(input (‘Enter the length of required list: '))
hitps:icolab research google conv/rivel hiOmujECqBu2q6y4L.N38319h_WUCZ0UZ7usp=sharingtscroTo“
19122‘nvs0/2020 Dhnuvkikan.pynt - Colaboratry
for x in range(n):
keint(input('Enter element: '))
L.append(k)
fin=int(input(‘Enter the number to be found: *))
print()
def Linear(1, fin):
count=0
for y in range(len(1)):
counte=1
if ly. 1
print (‘The number',fin, ‘is at*,y)
print(‘The number of steps required= ' count)
break
Linear(1,fin)
# Part b) finished
Enter the length of required list: 9
Enter element:
Enter elenent
Enter element
Enter elenent
Enter elenent
Enter elenent
Enter elenent
Enter elenent:
Enter element: 9
Enter the number to be found: 9
eVanukunn
‘The nunber 9 is at 8
The number of steps required= 9
# Part c) start
1
nt(input("Enter the length of required list: '))
for x in range(n):
nt(input('Enter element: *))
L.append(k)
def bin(1,m,start,end):
global count
count=0
if end>=start:
count+=1
mid=(start+end) //2
if I[mid]==m:
count+=1
return nid
elif 1[mid]>m:
count+=1
return bin(1,m,start,mid-1)
elif L[mid] select*from watches;
| WatchiD | Watch Nome | Price | Type | Stored ty |
| woet | High Time | 10000 | Unisex | 200 |
| weer | Life Time | 15000 | Ladies | 150 |
| woos | Wave | 20000 | Gents | 200 |
| woos | High Fashion | 7000 | Unisex | 20 |
| woes | Golden Tine | 2500 | Gents | 200 |
5 nous in set (2.00 sec)
mysql> select*from sale
| WatchID | Qty Sold | Quarter |
| wor | 20 | =]
| woos | 5 | 1]
| woz | 20 | 21
| woes | 19 | 21
| weer | 15 | 31
| wor | 20 | 2]
| woos | 19 | 3]
| woos | aw | al
8 rows in set (0.00 sec)
mysql> select w.Watch Name, s.Oty Sold from watches u,sale s where Quarter=
| Watch Name | Qty Sold |
| High Time | u
| Wave
2 rows in set (0.01 sec)
os
Database management question 1 part ii) |
le s where w.WatchID=s.hatchID and Watch Name Like ‘Tine’
woot | High Time | 10000 | Unisex |
woot | High Time | 10000 | Unisex |
weer | Life Time | 15000 | Ledies |
wooz | Life Time | 15000 | Ladies |
woos | Golden Time | 2500 | Gents |
[5 rows in set (0.01 sec)
Database management question 1 part iii) |
hitps:icolab research. google com/crivel hiOmufECqBu2q4yal. h38319h_WUC20UZ7usp=sharingiscrolTorkézihz7JKMoW
WatchID | Watch Name | Price | Type | Stored Qty | Qty Sold | Quarter
‘and w.MatchID-s.WatchID;
‘sql> select w.WatchID, w.Watch None, w.Price, w.Type, w.Stored Qty, s.Qty Sold, s.Quarter from watches w, sal
19122‘wraor2020 Diruvkkan pynb -Colaboratory
sql> select sum(Stored_Qty) from watches where Type like ‘Unisex’
5 x
| sum(Stored_Qty) |
Databse management question 1 part iv) |
Inysql> select Watch_Name, Price from watches where Price between 5000 and 10000;
| Watch_Name | Price |
Le
| High Time | 100¢e |
|| High Fashion | 700@ |
Le See
l2 rows in set (0.00 sec)
Database management question 1 part v) |
mysql> select WatchID, Qty_Sold from sale group by WatchID;
fee = =
| WatchID | Qty_Sold |
| weet | 10 |
| wee2 | 20 |
| wees | 5 |
|
rows in set (@.0@ sec)
Database management question 2 |
import mysql.connector
nydatabase=nysql.connector.connect(host=" localhost' ,user='root’ ,passwd='pass" , database="cb
mycursor=nydatabase. cursor()
def insert(itemcod, itennan, price):
ins=("Insert into item values(itemcode,itennane,price) values(%s,%s,%s)")
Ll
L.append(itemcod)
1. append( itennam)
L.append(price)
val=tunle/1)
hitps:iicolab.research.gongle.com/crivel hiOmuECqu2q4yal. h38319h_WUCz20UZ7usp=sharingiserolTorkézihz7JKMoW 20122‘9012020 DDhruvckan jpynb-Colaboratory
mycursor.execute(ins, val)
nydatabase. commit
def disp():
mycursor.execute( ‘select*from item’)
for x in mycurso
print (x)
def search(searchiten)
mycursor.execute('select*from item’)
for x in mycursor
if searchitem==str(x):
print(*Record found! ')
els
print(*Record not found
while True:
print(‘Type Display to view the items; Search to search for a record; Insert to enter
=str(input('Enter process: '))
if ke="Search
searchitem=str(input('Enter item to be searched: '))
search(searchitem)
elif k=="Display
disp()
Insert’
str(insert(‘Enter item code: '))
str(insert(‘Enter item name: '))
price=float(input('Enter the price: *))
insert (itemcod, itennam, price)
Quit’:
hitpsiicolab research google convrivel hiOmujECqBu2q4y4l. h38319h_WUCzZ0UZ7usp=sharingtscrolT
21122