0% found this document useful (0 votes)
61 views38 pages

Final List

Uploaded by

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

Final List

Uploaded by

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

Topic Page

1) Python Practicals..…………………………. 2
• Program 1…………….……………………….. 2
• Program 2……………………………………… 5
• Program 3……………………………………… 6
• Program 4……………………………………… 8
• Program 5……………………………………… 11
• Program 6……………………………………... 13
• Program 7……………………………………… 15
• Program 8……………………………………… 17
• Program 9……………………………………… 19
• Program 10……………………………………. 20
• Program 11……………………………………. 22
• Program 12……………………………………. 25
• Program 13……………………………………. 26
• Program 14……………………………………. 27
2) SQL………………….……………………………. 29
• Program 1……………………………………… 29
• Program 2………………………................ 31
• Program 3…………………………………….. 33
• Program 4…………………………………….. 35

Page 1 of 38
Program 1:
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 10th character onwards.
e) Read and display a line from the file. Ask user to provide the line number to
be read.
Find the frequency of words beginning with every letter.

Solution:

f=open('textfile.txt','w') #Making Text File


f.write("""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.\n""")
f.close()
#-------------------------------------------------------------------------------
f=open('textfile.txt','r') #Reading text file
print(f.read())
f.close()
#-------------------------------------------------------------------------------
f=open('textfile.txt','a') #Adding own Text
f.write("A bird has to fall down before flying.\n")
f.close()
#-------------------------------------------------------------------------------
f=open('textfile.txt')
lines=f.readlines()
print(lines[-1])
print(lines[0][9:])
n=int(input("Enter the line number to be printed: "))

Page 2 of 38
try: print(lines[n-1])
except: print("Line is not present.")
#-------------------------------------------------------------------------------
d={}
for i in lines:
for j in i.split():
if j[0].lower() in d: d[j[0].lower()]+=1
else: d[j[0].lower()]=1
for i in range(26):
try: print('Words beginning with',chr(97+i)+':',d[chr(97+i)])
except: continue
f.close()

Output:

Page 3 of 38
Page 4 of 38
Program 2:
Assume that a text file named file1.txt contains some text, write a function named
isvowel( ) that reads the file file1.txt and creates a new file named file2.txt, which shall contain
only those words from the file file1.txt which don’t start with a vowel
For example, if the file1.txt contains:
Carry Umbrella and Overcoat When it Rains
Then the file file2.txt shall contain
Carry When Rains

Solution:
def isvowel(fn):
f1=open(fn,'r')
t=f1.readlines()
v="aeoiuAEIOU"
print("First file has:",t)
x=''
for i in t:
for j in i.split():
if j[0] not in v:
x+=j
x+=" "
x+="\n"
f1.close()
f2=open("Copy.txt",'w')
f2.writelines(x)
f2.close()
f2=open("Copy.txt",'r')
for i in range(len(t)):
print(f2.read())
f2.close()
isvowel("Ans2.txt")

Output:

Page 5 of 38
Program 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 second name, a registration number, no of years and a
department separated by tabs.
a) Write a Python program that will copy the contents of the file into a list of tuples
b) Display full details of the student sorted by registration number
· The names of all students with no of year less than 3
· The number of people in each department

Solution:

f=open("file3.txt","r")
l=[]
for i in f.readlines():
t=tuple()
for j in i.split("/t"):
t+=(j,)
l.append(t)
print(l)

#(b) Display full details of the student sorted by registration number


Q1=input("Do you want to see details of students sorted by registration nmber:")
if Q1.lower() in ["1","y","yes"]:
k=[]
for i in l:
k.append(i[0])
k.sort()
for i in k:
for j in l:
if j[0]==i:
for h in j:
print(h,end=" ")
print()
else:
pass
#(c)The names of all students with no of year less than 3
Q2=input("Do you want to see the names of all students with no of year less than 3:")
if Q1.lower() in ["1","y","yes"]:
for i in l:
if i[0]<4:
print(i[0])

Page 6 of 38
Output:

Page 7 of 38
Program 4:
Write is a program that reads a file“myfile.txt” and builds a histogram (a dictionary having key
value pair 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 “myfile.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.

Solution:

def histogram(c):
f1=open(c,'r')
t=f1.read()
y,d=[],{}
for i in t.split():
c=0
for j in range(len(t.split())):
x=t.split()[j]
if i==x and i not in y:
c+=1
if i not in y:
d[i]=c
y.append(i)
f1.close()
return(d)
print("a)",histogram("myfile.txt"))
print()
a,y,c,s=0,0,0,''
x=histogram("myfile.txt")
for i in x:
c+=int(x[i])
y+=1
for j in x:
f=int(x[i])
if x[j]>f:
a=x[j]
s=j
print("iii)Most frequent word is","'",s,"'"),print()
print("i)Total no of words in the file is",c),print()
print("ii)No of different words is",y),print()
x=histogram("myfile.txt")
l,d=[],{}

Page 8 of 38
for i in x:
n=len(i)
l.append(i)
print(l)
for i in x:
a=len(i)
for j in l:
b=len(j)
if len(i)==len(j):
if len(j) not in d.keys():
d[len(j)]=[j]
l.remove(j)
else:
d[len(j)]=d[len(j)]+[j]
l.remove(j)
print(),print("b)",d),print()
'''def find_longest_word():
y=max(d.keys()) ,
print("The Longest words are:",d[y])
find_longest_word()'''

def find_longest_word():
maxnum=0
for number in d:
if number>maxnum:
maxnum=number
print("longest words of file:",(d[maxnum].split()))
#find_longest_word()

def filter_long_words(n):
for i in d:
if i>n:
print(d[i])
filter_long_words(int(input("Enter Your lower limit:")))

Output:

Page 9 of 38
Page 10 of 38
Program 5:
A dictionary Customer contains the following keys {roomno, name,duration}
A binary file “hotel.dat” contains details of customer checked in the hotel.
Write 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.

Solution:

import pickle
customer={"Roomno":[12,1,21,21,21,7,4,98,6],\
"Name":["Ap","As","Bn","Cn","Gn","Pw",\
"Dc","Kb","Dy"],"Duration":["2 days","3 days",\
"4 days",\
"4 days","4 days","1 days","2 days",\
"12 days","3 days"]}
#i)
f=open("hotel.dat","wb")
pickle.dump(customer,f)
f.close()
#ii)
f=open("hotel.dat","rb")
d=pickle.load(f)
for i in d:
print(i,":",d[i])
f.close()
#iii)
f=open("hotel.dat","rb")
D=pickle.load(f)
print("Number of customers :",len(D["Name"]))
f.close()
#iv)
f=open("hotel.dat","rb")
di=pickle.load(f)
a=di["Name"]
b=di["Duration"]

l1=len(b)
print("\nPassenger who stayed for more than 2 days:")
for i in range (l1):
temp=b[i].split()
x=int(temp[0])
if x>2:
print(a[i])

Page 11 of 38
Output:

Page 12 of 38
Program 6:
Sun Microsystems when held recruitment test. The file placement.csv containing the below
format of data
The marks are from 5 different tests conducted and each col is out of 5 marks
SNO NAME MARKS1 MARKS2 MARKS3 MARKS4 MARKS5
1 JOHN 4 3 4 2 5
2 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

c) Write the UDF to find the top n Names on basis of total Marks

Solution:

import csv
f=open("replacement.csv",'r') #File Opened
a=csv.reader(f)
l=[]
for i in a:
print(i)
l=l+[i]
people=l[1:] #List of records of people removing heading
#Part 1

def people_count(): #People count function


c=0 # c is counter for people
for i in people:
c=c+1
return c
print("Total no. of people who came for the placement test :",people_count())

#Part2
def top():
max_marks=0
marks=0 #Marks counter
for i in people :
for k in range(2,7):
marks=marks+int(i[k])
if marks > max_marks : #Comparing Marks
max_marks=marks
top1=i[1] #Name stored
marks=0
return top1
print("Highest Marks scored by :",top())

Page 13 of 38
Output:

Page 14 of 38
Program 7:
Write a program to input a number and then call the functions 3
count(n) which returns the number of digits
reverse(n) which returns the reverse of a number
hasdigit(n) which returns True if the number has a digit else False
show(n) to show the number as sum of place values of the digits of the number.

Solution:

def count(n):
c=0
for i in str(n):
c=c+1
return c

def reverse(n):
t=str(n)
a=t[::-1]
return a

def hasdigit(n):
r=0
x=int(input("Enter the digit to be found: "))
while n!=0:
r=n%10
if r==x:
return True
break
n=n//10
else:
return False
def show(n):
n=str(n)
c=-1
s=""
q="+"
for i in n:
c=c+1
for i in n:
if i == n[-1]:
q=""
s=s+str((10**c)*int(i))+q
c=c-1
return s
n=int(input("Enter a number: "))
print("Number of digits: ",count(n))
print("Reverse of a digit ",reverse(n))
print("Does the number has a digit ",hasdigit(n))
print(n,"=",show(n))

Page 15 of 38
Output:

Page 16 of 38
Program 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.
For example: 6 = 1+2+3 and 28=1+2+4+7+14 Number is a prime number if it 's factors are 1
and itself. Write functions
i) Generatefactors() to populate a list of factors
ii) isPrimeNo() to check whether the number is prime number or not
iii) isPerfectNo() to check whether the number is perfect number or not
Save the above as a module perfect.py and use in the program main.py as a menu driven
program.

Solution:
#perfect.py
def Generatefactors(n):
l=[]
for i in range(1,n+1):
if n%i==0:
l.append(i)
return(l)

def isPrime(n):
l=Generatefactors(n)
if len(l)==2 and 1 and n in l:
print("i)", "No. is a Prime No.")
else:
print("i)","No. is not a Prime No.")

def isPerfectNo(n):
l=Generatefactors(n)
x=0
for i in l:
x+=i
if x==2*n:
print("iii)","No. is a Perfect No.")
else:
print("iii)","No. is not a perfect No.")

#new file
import perfect
print('''Input Prime if you want to check if the entered no. is prime or not \n
Perfect if you want to check if the entered no. is perfect or not \nPe
List if you want to see a list of all factors of that number''' )

x=input("Enter Your Choice :")


n=int(input("Enter Your No. :"))
if x=="Prime":
perfect.isPrime(n)
elif x=="Perfect":
perfect.isPerfectNo(n)

Page 17 of 38
elif x=="List":
print(perfect.Generatefactors(n))
else:
print("Invalid Choice. Pls try again")

Output:

Page 18 of 38
Program 9:
Pascal’s triangle is a number triangle with numbers arranged in staggered rows such that
anr=n!/r!(n−r)!
This equation is the equation for a binomial coefficient. Write a function in Python to print the
Pascal Triangle

Solution:

def fact(n):
p=1
for i in range(1,n+1):
p*=i
return(p)
def pascal(k):
for i in range(k):
print(" "*(k-i),end="")
for j in range(i+1):
x=fact(i)/(fact(j)*fact(i-j))
print(int(x),end=" ")
print()
pascal(5)

Output:

Page 19 of 38
Program 10:
Data can be represented in memory in different ways Binary, Decimal, Octal, and
Hexadecimal. Input number in decimal and desired type (Specify B for Binary, O for Octal, H
for Hexadecimal) for output. Write a function to perform the conversions
SAMPLE INPUT 12
DESIRED TYPE B
Result: 1100
SAMPLE INPUT 25
DESIRED TYPE O
Result: 31

Solution:

def converter(n,t):
if t=="h":
u=16
elif t=="o":
u=8
elif t=="b":
u=2

b=int(n)
s=""
while b!=0:
a=b%u
if a>9:
a=chr(a-9+64)
s+=str(a)
b=b//u
s=s[::-1]
k=""
c=n-int(n)
l=[]
while c not in l and c!=0:
c=u*c
q=int(c)
k+=str(q)
l+=(q)
c=c-int(c)
if len(k)==0:
print(s)
else:
print(s+"."+k)

n=float(input("Enter the no."))


s=input("Enter the number system (h/o/b): ")
converter(n,s)

Page 20 of 38
Output:

Page 21 of 38
Program 11:
Write a program to input a list and write the function for the following:
i) To sort list using bubble sort.
ii) To search an element using binary search.
iii) To search an element using linear search.

Solution:

list1=[]
n=int(input("enter no. of elements in list: "))
i=0
while i<n:
x=int(input("enter the elements of your list: "))
list1.append(x)
i=i+1
print(list1)

def bubbleSort(list1):
for i in range(len(list1)):
for j in range(0, len(list1) - i - 1):
# To sort in descending order, change > to < in this line.
if list1[j] > list1[j + 1]:
# swap if greater is at the rear position
(list1[j], list1[j + 1]) = (list1[j + 1], list1[j])
print(list1)

def binary_search(list1):
n=int(input(' number :'))
c=False
low=0
high=len(list1)-1
while high >= low and c==False:
mid=(low+high)//2
if list1[mid]==n:
c=True
elif list1[mid]>n:
high=mid-1
elif list1[mid]<n:
low=mid+1
if c==True:
print('present ')
else:
print('not present ')

def linear_search(list1):
x=int(input("number: "))
if x in list1:

Page 22 of 38
print(x," is present at ",list1.index(x))
else:
print("not present")

print("1.bubble sort \n 2.binary search \n 3.linear search" )


u=int(input("enter your choice: "))
if u==1:
bubbleSort(list1)
elif u==2:
binary_search(list1)
elif u==3:
linear_search(list1)
else:
print("invalid input")

Output:

Page 23 of 38
Page 24 of 38
Program 12:
Create a graphical application for Simple Interest Calculator that accepts user inputs for P, R
and T. Calculate Simple Interest writes the output using a message box on the screen. Use the
tkinter library.

Solution:

import tkinter
global principle,rate,time
def s():
si=(float(principle)*float(rate)*float(time)/100)
tkinter.messagebox.showinfo('SIMPLE INTEREST ',str(si))
a=tkinter.Tk()
a.title('Simple Interest')
a.geometry('800x300')
label=tkinter.Label(a,text="SIMPLE INTEREST CALCULATOR",font=("ALGERIAN",30))
label.grid(column=1,row=0)
label1=tkinter.Label(a,text="Principle",font=("Comic Sans MS",20))
label1.grid(column=0,row=1)
principle=tkinter.Entry(a,width=20,borderwidth=2,font=("Comic Sans MS",20))
principle.grid(column=1,row=1)
label2=tkinter.Label(a,text="Rate",font=("Comic Sans MS",20))
label2.grid(column=0,row=2)
rate=tkinter.Entry(a,width=20,borderwidth=2,font=("Comic Sans MS",20))
rate.grid(column=1,row=2)
label3=tkinter.Label(a,text="Time",font=("Comic Sans MS",20))
label3.grid(column=0,row=3)
time=tkinter.Entry(a,width=20,borderwidth=2,font=("Comic Sans MS",20))
time.grid(column=1,row=3)
b=tkinter.Button(a,text="Submit",font=("Comic Sans MS",20),command=s)
b.grid(column=1,row=4)
a.mainloop()
Output:

Page 25 of 38
Program 13:
Create a stack to take in stack of numbers and then simulate a ring game.
A ring stand is such that only a ring of higher diameter can be placed on lower one. The
diameters are given by the user the program will compare the diameter of ring at stack top with
the diameter of ring to be placed if condition specified is true ring is added to the stack
otherwise keep popping and put them into temporary ring stand to arrange them into specific
order.

Solution:

l=[]
templ=[]
stopper=1
print("welcome to the ring game")
while stopper!=0:
d=int(input("enter the diameter of the ring: "))
if len(l)==0:
l.append(d)
else:
if d<l[len(l)-1]:
l.append(d)
print("ring added!")
else:
print("the ring is not smaller than the top ring, hence not added")
templ.append(d)
print("do you wish to continue, if yes press any number ,else press 0")
print("temporary stack: ",templ)
print("main stack: ",l)
stopper=int(input("enter your choice"))

Output:

Page 26 of 38
Program 14:
Create a stack to take in stack of numbers and then simulate a ring game.
A ring stand is such that only a ring of higher diameter can be placed on lower one. The
diameters are given by the user the program will compare the diameter of ring at stack top with
the diameter of ring to be placed if condition specified is true ring is added to the stack
otherwise keep popping and put them into temporary ring stand to arrange them into specific
order.

Solution:

l=[]
templ=[]
stopper=1
print("welcome to the ring game")
while stopper!=0:
d=int(input("enter the diameter of the ring: "))
if len(l)==0:
l.append(d)
else:
if d<l[len(l)-1]:
l.append(d)
print("ring added!")
else:
print("the ring is not smaller than the top ring, hence not added")
templ.append(d)
print("do you wish to continue, if yes press any number ,else press 0")
print("temporary stack: ",templ)
print("main stack: ",l)
stopper=int(input("enter your choice"))

Output:

Page 27 of 38
Page 28 of 38
1. Consider the following WATCHES and SALE table and Write the command in MYSQL for (i)
to (v):

i. To display watch name and their quantity sold in first quarter.

ii. To display the details of those watches whose name ends with ‘Time’?

Page 29 of 38
iii. To display total quantity in store of Unisex type watches.

iv. To display watch’s name and price of those watches which have price range in
between 5000-15000.

v. To display Quantity sold of all watches WatchId wise.

Page 30 of 38
2. Consider the table “ITEM” having the following fields
Itemcode varchar
Itemname varchar
Price float
i) Create the table ITEM in the mydb database

ii) Create a menu driven program in python to have


a) Function for inserting records in the table
b) Function for displaying all the records from the table item
c) Function for searching for a particular record on basis of Itemcode

def add():
print("Input your value in the form of (Itemcode,Itemname,Price)")
value=input("Enter the value to be added: ")
s="Insert into item value "+value+";"
command.execute(s)
mydb.commit()
def select():
command.execute("Select * from item;")
for i in command:
print(i)
def find():
item=input("Enter the itemcode: ")
command.execute("Select * from item;")
for i in command:
if item==i[0]:
print("Item found")
print(i)
break
Page 31 of 38
else:
print("element not found")
c="y"
while c=="y":
print("""Choose 1 to add values,
2 to display all the values in table
3 to search for a particular record on the basis of itemcode""")
c2=int(input("Enter your choice: "))
if c2==1:
add()
elif c2==2:
select()
elif c2==3:
find()
else:
print("Wrong choice pls choose correctly")
c=input("Enter y if you want to continue: ")

Page 32 of 38
3. Create a Table “STUDENT” in MySQL with the following attributes.

i. Create a menu driven program in Python for the user to enter the details and save the
data in MySQL table
ii. Allow the user to update the details for a particular rollno and ensure the changes
have been made in the table student.

import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="hello",database="CS"
)
command=mydb.cursor()

c="y"
while c=="y":
print("""Choose 1 to enter new entry
2 for updating an entry""")
cond=int(input("Enter your choice: "))
if cond==1:
print("Input your value in the form of (RollNo,Name,Class,DOB,Gender)")
value=input("Enter the value to be added: ")
s="Insert into student value "+value+";"
print(s)
command.execute(s)

Page 33 of 38
mydb.commit()
elif cond==2:
item=int(input("Enter the rollno: "))
command.execute("Select * from student;")
for i in command:
if item==i[0]:
input1=eval(input("Enter changes in the form (RollNo,Name,Class,DOB,Gender):
"))
str1="update student set
Name='"+str(input1[1])+"',Class="+str(input1[2])+",DOB='"
str2=str1+input1[3]+"',Gender='"+input1[4]+"' where RollNo ="+str(input1[0])
print(str2)
command.execute(str2)
else:
print("Roll No not found")
command.execute("Select * from student;")
print("The updated table is :")
for i in command:
print(i)
mydb.commit()
c=input("Enter y if you want to continue: ")
if c!="y":
mydb.close()

Page 34 of 38
4.Create a Table “BUS” in MySQL with the following attributes.

Table: BUS
ColumnName Datatype Constraint
BusNo Number Primary Key
Origin Varchar
Dest Varchar
Rate Number
Km Number

Now build a connection with Python to add a new record and Display the details in above table.
Use Tkinter to create the front end.

Solution:

import tkinter
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='host',database='file')
mycursor=mydb.cursor()
def exita():
a.destroy()
def exitb():
b.destroy
def submit():
num,orig,des,r,km=bus_num.get(),origin.get(),Dest.get(),Rate.get(),Km.get()
if num=='':
label=tkinter.Label(b,text="Mention Bus No",font=("Comic Sans MS",10))
label.grid(column=3,row=2)
else:
x=str(num)+','+'\''+str(orig)+'\''+','+'\''+str(des)+'\''+','+str(r)+','+str(km)
print(x)
mycursor.execute('Insert into BUS Values ('+x+');')
mydb.commit()
exitb()
first()

Page 35 of 38
def add():
global bus_num,origin,Dest,Rate,Km,b
exita()
b=tkinter.Tk()
b.title('BUS RECORDS')
b.geometry('800x500')
label=tkinter.Label(b,text="ADDING RECORDS",font=("ALGERIAN",30))
label.grid(column=1,row=0)
label1=tkinter.Label(b,text="Bus Number",font=("Comic Sans MS",20))
label1.grid(column=1,row=2)
bus_num=tkinter.Entry(b,width=20,borderwidth=2,font=("Comic Sans MS",20))
bus_num.grid(column=2,row=2)
label2=tkinter.Label(b,text="Origin",font=("Comic Sans MS",20))
label2.grid(column=1,row=3)
origin=tkinter.Entry(b,width=20,borderwidth=2,font=("Comic Sans MS",20))
origin.grid(column=2,row=3)
label3=tkinter.Label(b,text="Destination ",font=("Comic Sans MS",20))
label3.grid(column=1,row=4)
Dest=tkinter.Entry(b,width=20,borderwidth=2,font=("Comic Sans MS",20))
Dest.grid(column=2,row=4)
label4=tkinter.Label(b,text="Rate",font=("Comic Sans MS",20))
label4.grid(column=1,row=5)
Rate=tkinter.Entry(b,width=20,borderwidth=2,font=("Comic Sans MS",20))
Rate.grid(column=2,row=5)
label5=tkinter.Label(b,text="Km",font=("Comic Sans MS",20))
label5.grid(column=1,row=6)
Km=tkinter.Entry(b,width=20,borderwidth=2,font=("Comic Sans MS",20))
Km.grid(column=2,row=6)
b1=tkinter.Button(b,text="Submit",font=("Comic Sans MS",20),command=submit)
b1.grid(column=0,row=7)

Page 36 of 38
b1=tkinter.Button(b,text="Back",font=("Comic Sans MS",20),command=first)
b1.grid(column=1,row=7)
b.mainloop()
def display():
global c
c=tkinter.Tk()
c.title('BUS RECORDS')
c.geometry('500x500')
label=tkinter.Label(c,text="RECORDS",font=("Comic Sans MS",30))
label.grid(column=1,row=0)
mycursor.execute('SELECT * from BUS')
records=mycursor.fetchall()
if records==[]:
label=tkinter.Label(c,text="No records found",font=("Comic Sans MS",20))
label.grid(column=1,row=0)
else:
r=1
for i in records:
i=str(i)
label=tkinter.Label(c,text=i,font=("Comic Sans MS",15))
label.grid(column=1,row=r)
r=r+1
b1=tkinter.Button(c,text="Back",font=("Comic Sans MS",15),command=first)
b1.grid(column=0,row=7)
def first():
global a
try:
a.destroy()
except:
pass

Page 37 of 38
try:
b.destroy()
except:
pass
try:
c.destroy()
except:
pass
a=tkinter.Tk()
a.title("BUS Records")
a.geometry('450x160')
label=tkinter.Label(a,text="BUS",font=("ALGERIAN",30))
label.grid(column=1,row=0)
b1=tkinter.Button(a,text="ADD RECORD",font=("Comic Sans MS",15),command=add)
b1.grid(column=0,row=1)
b2=tkinter.Button(a,text='DISPLAY RECORDS',font=("Comic Sans
MS",15),command=display)
b2.grid(row=1,column=2)
b3=tkinter.Button(a,text='Exit',font=("Comic Sans MS",15),command=exita)
b3.grid(row=4,column=1)
a.mainloop()
first()

Page 38 of 38

You might also like