Gr.12 Practical Questions and Source Code
Gr.12 Practical Questions and Source Code
SOURCE CODE:
def multiply(list):
prod=1
for element in list:
prod*=element
print("product of all the elements in the list is ",prod)
def add(list):
sum_evenpos=sum_oddpos=0
for i in range(0,len(list)):#starts the positions from 0
if i%2==0:
sum_evenpos+=list[i]
else:
sum_oddpos+=list[i]
print("sum of elements at even position numbers = " ,sum_evenpos)
print("sum of elements at odd position numbers = " ,sum_oddpos)
def addendswith7(list):
sum=0
for i in list:
if i%10==7:
sum+=i
print("Sum of the elements ends with 7 in the list =" , sum)
#main segment
1
list=eval(input("enter the integer list "))
while True:
print("Menu :")
print("1: Multiply all the numbers in a list ")
print("2: Add alternate elements in the list" )
print("3: add all elements ended with 7 in the list ")
print("4: Exit")
ch=int(input("enter choice"))
if ch==1:
multiply(list)
elif ch==2:
add(list)
elif ch==3:
addendswith7(list)
else:
break
OUTPUT:
enter the integer list [1,2,3,4,7,17]
Menu :
1: Multiply all the numbers in a list
2: Add alternate elements in the list
3: add all elements ended with 7 in the list
4: Exit
enter choice1
product of all the elements in the list is 2856
Menu :
1: Multiply all the numbers in a list
2: Add alternate elements in the list
3: add all elements ended with 7 in the list
4: Exit
enter choice2
sum of elements at even position numbers = 11
2
sum of elements at odd position numbers = 23
Menu :
1: Multiply all the numbers in a list
2: Add alternate elements in the list
3: add all elements ended with 7 in the list
4: Exit
enter choice3
Sum of the elements ends with 7 in the list = 24
Menu :
1: Multiply all the numbers in a list
2: Add alternate elements in the list
3: add all elements ended with 7 in the list
4: Exit
enter choice4
3
2. Create a text file “story.txt” using Python. The file may contain trailing and leading
white spaces.
Write a Menu driven Python program:
(i) To display the size of the file after removing EOL characters, leading and
trailing white spaces and blank lines.
(ii) To read the file line by line and display each word separated by a #.
(iii) To count the number of “Me” or “My” words present in the above file.
SOURCE CODE:
def sizeoffile(filename):
with open(filename,'r') as file:
totalsize=0
size=0
for line in file: #reads one line at a time and adds it to line variable.
totalsize+=len(line)
size+=len(line.strip()) #strip will remove leading and trailing white spaces
print("The total size of the file =", totalsize)
print("Size of the file after removing leading and trailing white spaces =", size)
def wordseperate(filename):
with open(filename,'r') as file:
str=''
for line in file:
words=line.split() #split() - will convert line into list of words
#join() - joins the character between list of words and returns a string
value
str+='#'.join(words)
print("The file contents are:")
print(str)
4
def countmemy(filename):
with open(filename,'r') as file:
mecount=mycount=0
content=file.read() #reads all the contents of the file
list=content.split()
for word in list:
if word.lower()=='me':
mecount+=1
elif word.lower()=='my':
mycount+=1
print(" Me count =", mecount)
print("My count =", mycount)
print("Me and my count =", (mecount+mycount))
#main segment
with open("sample.txt",'w') as file:
n=int(input("Enter how many lines you want to enter"))
for i in range(n):
line=input("Enter a line of text which may contain leading and trailing white
spaces")
file.write(line+'\n')
filename="sample.txt"
while True:
print("Menu :")
print("1: To display the size of the file after removing EOL characters,\
leading and trailing white spaces and blank lines.")
print("2: To read the file line by line and display each word separated by a #" )
print("3: To count the number of “Me” or “My” words present in the file ")
print("4: Exit")
ch=int(input("enter choice"))
if ch==1:
sizeoffile(filename)
elif ch==2:
5
wordseperate(filename)
elif ch==3:
countmemy(filename)
else:
break
OUTPUT:
Enter how many lines you want to enter3
Enter a line of text which may contain leading and trailing white spaces This is the
first line me
Enter a line of text which may contain leading and trailing white spaces This is
the second line my
Enter a line of text which may contain leading and trailing white spacesme my me my
third line
Menu :
1: To display the size of the file after removing EOL characters,leading and trailing
white spaces and blank lines.
2: To read the file line by line and display each word separated by a #
3: To count the number of “Me” or “My” words present in the file
4: Exit
enter choice1
The total size of the file = 96
Size of the file after removing leading and trailing white spaces = 73
Menu :
1: To display the size of the file after removing EOL characters,leading and trailing
white spaces and blank lines.
2: To read the file line by line and display each word separated by a #
3: To count the number of “Me” or “My” words present in the file
4: Exit
enter choice2
The file contents are:
This#is#the#first#line#meThis#is#the#second#line#myme#my#me#my#third#line
6
Menu :
1: To display the size of the file after removing EOL characters,leading and trailing
white spaces and blank lines.
2: To read the file line by line and display each word separated by a #
3: To count the number of “Me” or “My” words present in the file
4: Exit
enter choice3
Me count = 3
My count = 3
Me and my count = 6
7
3. Create a text file “sample.txt” using Python. The file could contain minimum 4
lines, and few lines can start with the character ‘A’.
Write a Menu driven Python program:
(i)To display the number of the lines in the file.
(ii) To display the number of words and white spaces in the file.
(iii)To display the number of lines starting with the letter ‘A’ or ‘T’.
SOURCE CODE:
def nooflines(filename):
with open(filename,'r') as file:
linescount=0
for line in file: #reads one line at a time and adds it to line variable.
linescount+=1
print("The number of lines in the file =", linescount)
def wordscount(filename):
with open(filename,'r') as file:
wordcount=0
for line in file:
words=line.split() #split() - will convert line into list of words
wordcount+=len(words)
print("The number of words in the file =" , wordcount)
print("The number of whitespaces in the file =" , wordcount-1)
8
def countlineswithAT(filename):
with open(filename,'r') as file:
linescount=0
for line in file: #reads one line at a time and adds it to line variable.
if line.lower().startswith('a') or line.lower().startswith('t'):
linescount+=1
print("The number of lines in the file starts with 'a' or 't' =", linescount)
#main segment
with open("sample.txt",'w') as file:
ans='yes'
while ans.lower()=='yes':
line=input("Enter a line of text ")
file.write(line+'\n')
ans=input("Do you want to enter one more line? yes/no")
filename="sample.txt"
while True:
print("Menu :")
print("1: To display the number of the lines in the file.")
print("2: To display the number of words and white spaces in the file." )
print("3: To display the number of lines starting with the letter ‘A’ or ‘T’ ")
print("4: Exit")
ch=int(input("enter choice"))
if ch==1:
nooflines(filename)
elif ch==2:
wordscount(filename)
elif ch==3:
countlineswithAT(filename)
else:
break
OUTPUT:
9
Enter a line of text A for Apple
Do you want to enter one more line? yes/noyes
Enter a line of text B for Boy
Do you want to enter one more line? yes/noyes
Enter a line of text C for Cat
Do you want to enter one more line? yes/noyes
Enter a line of text This is the fourth line.
Do you want to enter one more line? yes/nono
Menu :
1: To display the number of the lines in the file.
2: To display the number of words and white spaces in the file.
3: To display the number of lines starting with the letter ‘A’ or ‘T’
4: Exit
enter choice1
The number of lines in the file = 4
Menu :
1: To display the number of the lines in the file.
2: To display the number of words and white spaces in the file.
3: To display the number of lines starting with the letter ‘A’ or ‘T’
4: Exit
enter choice2
The number of words in the file = 14
The number of whitespaces in the file = 13
Menu :
1: To display the number of the lines in the file.
2: To display the number of words and white spaces in the file.
3: To display the number of lines starting with the letter ‘A’ or ‘T’
4: Exit
enter choice3
The number of lines in the file starts with 'a' or 't' = 2
Menu :
1: To display the number of the lines in the file.
2: To display the number of words and white spaces in the file.
3: To display the number of lines starting with the letter ‘A’ or ‘T’
4: Exit
enter choice4
10
4. Create a text file “sample.txt” using Python.
Write a menu driven Python program:
(i) To write a function, vowelCount() in Python that counts and displays the number
of vowels in the text file.
(ii) Write a function in Python to read the text file, and displays those lines which
begin with the word ‘You’.
(iii) Write a function remove_lowercase( ) that accepts two filenames as infile
and outfile, and copies all lines that do not start with a lowercase letter from the
first file into the second.
SOURCE CODE:
def vowelCount(filename):
with open(filename,'r') as file:
vowelscount=0
str=file.read() #read() reads all the contents of the file and returns in the form of a
string.
vowels="aeiou"
for ch in str:
if ch.lower() in vowels:
vowelscount+=1
print("The number of vowels in the file =", vowelscount)
def linescountyou(filename):
11
with open(filename,'r') as file:
linecount=0
for line in file:
if line.lower().startswith('you'):
linecount+=1
print("The number of lines starting with the word 'you' =" , linecount)
def remove_lowercase(infile,outfile):
with open(infile,'r') as file1:
with open(outfile,'w') as file2:
for line in file1:
if line[0].isupper(): # if the line startswith upper case, then write the line in
the outfile.
file2.write(line)
#main segment
with open("sample.txt",'w') as file:
ans='yes'
while ans.lower()=='yes':
line=input("Enter a line of text ")
file.write(line+'\n')
ans=input("Do you want to enter one more line? yes/no")
filename="sample.txt"
while True:
print("Menu :")
print("1: To write a function, vowelCount() in Python that counts and displays the
number of vowels in the text file.")
print("2: To read the text file, and displays those lines which begin with the word
‘You’." )
print("3: function remove_lowercase( ) that accepts two filenames as infile and
outfile, \
and copies all lines that do not start with a lowercase letter from the first file into the
second ")
print("4: Exit")
12
ch=int(input("Enter your choice"))
if ch==1:
vowelCount(filename)
elif ch==2:
linescountyou(filename)
elif ch==3:
filename1='sample.txt'
filename2='outfile.txt'
remove_lowercase(filename1,filename2)
else:
break
OUTPUT:
Enter a line of text You are the best.
Do you want to enter one more line? yes/noyes
Enter a line of text This is the second line.
Do you want to enter one more line? yes/noyes
Enter a line of text You can do better.
Do you want to enter one more line? yes/nono
Menu :
1: To write a function, vowelCount() in Python that counts and displays the number of
vowels in the text file.
2: To read the text file, and displays those lines which begin with the word ‘You’.
3: function remove_lowercase( ) that accepts two filenames as infile and outfile, and
copies all lines that do not start with a lowercase letter from the first file into the
second
4: Exit
Enter your choice1
The number of vowels in the file = 19
Menu :
1: To write a function, vowelCount() in Python that counts and displays the number of
vowels in the text file.
2: To read the text file, and displays those lines which begin with the word ‘You’.
13
3: function remove_lowercase( ) that accepts two filenames as infile and outfile, and
copies all lines that do not start with a lowercase letter from the first file into the
second
4: Exit
Enter your choice2
The number of lines starting with the word 'you' = 2
Menu :
1: To write a function, vowelCount() in Python that counts and displays the number of
vowels in the text file.
2: To read the text file, and displays those lines which begin with the word ‘You’.
3: function remove_lowercase( ) that accepts two filenames as infile and outfile, and
copies all lines that do not start with a lowercase letter from the first file into the
second
4: Exit
Enter your choice3
Menu :
1: To write a function, vowelCount() in Python that counts and displays the number of
vowels in the text file.
2: To read the text file, and displays those lines which begin with the word ‘You’.
3: function remove_lowercase( ) that accepts two filenames as infile and outfile, and
copies all lines that do not start with a lowercase letter from the first file into the
second
4: Exit
Enter your choice4
14
5. Write a menu based Python program using Binary file concept:
(i)To add student details (rollno, sname and aggregate marks) .
(ii) Search for a particular student and display his/her complete details.
Otherwise, display the appropriate message.
(iii) Update the student marks for the given rollno.
(iv) Display the contents of the file.
SOURCE CODE:
import pickle
def add():
file=open("stud.dat",'ab')
ans='y'
while ans=='y':
rollno=int(input("Enter rollno"))
name=input("Enter student name")
marks=int(input("Enter student's Average marks"))
list=[rollno,name,marks]
pickle.dump(list,file)
ans=input("Do you want to enter more records? Enter y or n")
file.close()
def search():
rollno=int(input("Enter the student rollno you want to search"))
fin=open("stud.dat",'rb')
found=False
try:
while True:
list=pickle.load(fin) # load() will return one record at a time
if list[0]==rollno:
print("Search Successful, The student details are")
print(list[0],list[1],list[2])
found=True
except EOFError:
if found==False:
print("Search Unsuccessful")
fin.close()
def update():
15
rollno=int(input("Enter the student rollno you want to update"))
fin=open("stud.dat",'rb+')
def display():
fin=open("stud.dat",'rb')
try:
print(" File Records are:")
while True:
rec=pickle.load(fin) # load() will return record by record
print(rec[0],rec[1],rec[2])
except:
fin.close()
#main segment
while True:
print("\nMenu for Binary file:")
print("1:Add the student record")
print("2:Search for a Record")
print("3:Update a record ")
print("4: Display the records")
print("5: Exit")
16
ch=int(input("enter choice"))
if ch==1:
add()
elif ch==2:
search()
elif ch==3:
update()
elif ch==4:
display()
else:
break
OUTPUT:
Menu for Binary file:
1:Add the student record
2:Search for a Record
3:Update a record
4: Display the records
5: Exit
enter choice1
Enter rollno101
Enter student nameSachin
Enter student's Average marks90
Do you want to enter more records? Enter y or ny
Enter rollno102
Enter student nameVarun
Enter student's Average marks67
Do you want to enter more records? Enter y or ny
Enter rollno103
Enter student nameNithya
Enter student's Average marks92
Do you want to enter more records? Enter y or nn
17
File Records are:
101 Sachin 90
102 Varun 67
103 Nithya 92
18
4: Display the records
5: Exit
enter choice3
Enter the student rollno you want to update102
Search Successful
Enter the new marks89
The record is successfully updated in the file
19
6. Write a menu based Python program using Binary file concept:
(i)To store Employee details (Empno,Ename and salary) in a binary file.
(ii)Search for a particular Employee and display the complete details of the
employee. Otherwise, display the appropriate message.
(iii) Update the Employee salary for the given employee number.
(iv) Display the contents of the file.
SOURCE CODE:
import pickle
def add():
file=open("employee.dat",'ab')
ans='y'
while ans=='y':
empno=int(input("Enter Employee no : "))
ename=input("Enter employee name: ")
salary=int(input("Enter employee salary: "))
list=[empno,ename,salary]
pickle.dump(list,file)
ans=input("Do you want to enter more records? Enter y or n: ")
file.close()
def search():
eno=int(input("Enter the empoyee number you want to search"))
fin=open("employee.dat",'rb')
found=False
try:
while True:
list=pickle.load(fin) # load() will return one record at a time
if list[0]==eno:
print("Search Successful, The employee details are")
print(list[0],list[1],list[2])
found=True
except EOFError:
if found==False:
20
print("Search Unsuccessful")
fin.close()
def update():
eno=int(input("Enter the employee number you want to update"))
fin=open("employee.dat",'rb+')
#(rb+ mode is compulsory for both read and update operations.)
found=False
try:
while True:
position=fin.tell()
list=pickle.load(fin) # load() will return one record at a time
if list[0]==eno:
print("Search Successful")
salary=int(input("Enter the new salary: "))
list[2]=salary
print("The updated employee record= ",list)
fin.seek(position)
pickle.dump(list,fin)
found=True
except EOFError:
if found==False:
print("Search Unsuccessful")
fin.close()
def display():
fin=open("employee.dat",'rb')
try:
print(" File Records are:")
while True:
rec=pickle.load(fin) # load() will return record by record
print(rec[0],rec[1],rec[2])
except:
fin.close()
21
#main segment
while True:
print("\n Menu :")
print("1: Add the records")
print("2: Search for a Record")
print("3: Update a record ")
print("4: Display the records")
print("5: Exit")
OUTPUT:
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :1
Enter Employee no : 200
Enter employee name: Sanjay
Enter employee salary: 55000
Do you want to enter more records? Enter y or n: y
Enter Employee no : 201
Enter employee name: Arun
Enter employee salary: 89000
Do you want to enter more records? Enter y or n: y
22
Enter Employee no : 202
Enter employee name: Karthik
Enter employee salary: 100000
Do you want to enter more records? Enter y or n: n
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :4
File Records are:
200 Sanjay 55000
201 Arun 89000
202 Karthik 100000
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :2
Enter the empoyee number you want to search300
Search Unsuccessful
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :2
Enter the empoyee number you want to search201
Search Successful, The employee details are
201 Arun 89000
Menu :
1: Add the records
23
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :3
Enter the employee number you want to update300
Search Unsuccessful
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :3
Enter the employee number you want to update201
Search Successful
Enter the new salary: 90000
The updated employee record= [201, 'Arun', 90000]
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :4
File Records are:
200 Sanjay 55000
201 Arun 90000
202 Karthik 100000
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :1
Enter Employee no : 207
24
Enter employee name: Rithvik
Enter employee salary: 67000
Do you want to enter more records? Enter y or n: n
Menu :
1: Add the records
2: Search for a Record
3: Update a record
4: Display the records
5: Exit
enter the choice :4
File Records are:
200 Sanjay 55000
201 Arun 90000
202 Karthik 100000
207 Rithvik 67000
25
7. Write a menu based Python program using CSV File concept:
File name : “Phone.csv”
(i) Create CSV file and store Customerno, Cname, Address and Phoneno.
(ii) Search any customerno and display the complete details of the customer. If
not, display the appropriate message.
(iii) Update the address of the customer whose address need to be changed.
(iv) Display the contents of the file.
SOURCE CODE:
import csv
def add():
file=open("phone.csv",'a',newline='')
csvwriter=csv.writer(file,delimiter=',')
ans='y'
while ans=='y':
cno=input("Enter customer number: ")
cname=input("Enter customer name: ")
address=input("Enter customer address: ")
phoneno=input("Enter customer phone number: ")
#Make a record- list of values
list=[cno,cname,address,phoneno]
csvwriter.writerow(list)
ans=input("Do you want to add more records? y or n")
file.close()
def search():
cno=input("Enter the Customer number you want to search: ")
fin=open("phone.csv",'r')
csvreader=csv.reader(fin)#returns a list of all the records from the file
#Where each record is a list of string values
for rec in csvreader:
if cno in rec[0]:
print("Search Successful, The customer details are")
print(rec[0],rec[1],rec[2],rec[3])
break
else:
26
print("The customer number does not exist in the file")
fin.close()
def update():
phone=[]
cno=input("Enter the customer number you want to update")
fin=open("phone.csv",'r+',newline='') #r+ mode is compulsory for read and update
csvreader=csv.reader(fin)
for rec in csvreader:
phone.append(rec)
fin.seek(0) #to move the file pointer to the beginning of the file and writes the
entire list once again
csvwriter=csv.writer(fin,delimiter=',')
csvwriter.writerows(phone) # overwrites the old content by the new content
fin.close()
def display():
fin=open("phone.csv",'r',newline='')
csvreader=csv.reader(fin)
for i in csvreader:
print(i[0],i[1],i[2],i[3])
fin.close()
#main segment
27
while True:
print("\n Menu :")
print("1:Add the records: ")
print("2:Search for a Record: ")
print("3:Update a record: ")
print("4: Display: ")
print("5: Exit: ")
OUTPUT:
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 1
Enter customer number: 400
Enter customer name: Aathira
Enter customer address: RM Nagar
Enter customer phone number: 9876545678
Do you want to add more records? y or ny
Enter customer number: 405
Enter customer name: Nixen
28
Enter customer address: Kasturinagar
Enter customer phone number: 9842234521
Do you want to add more records? y or nn
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 4
400 Aathira RM Nagar 9876545678
405 Nixen Kasturinagar 9842234521
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 2
Enter the Customer number you want to search: 500
The customer number does not exist in the file
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 2
Enter the Customer number you want to search: 405
Search Successful, The customer details are
405 Nixen Kasturinagar 9842234521
29
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 3
Enter the customer number you want to update500
The customer number does not exist in the file
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 3
Enter the customer number you want to update400
Search Successful
Enter the addressBabusapalya, Bangalore
The updated customer record= ['400', 'Aathira', 'Babusapalya, Bangalore',
'9876545678']
Menu :
1:Add the records:
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 4
400 Aathira Babusapalya, Bangalore 9876545678
405 Nixen Kasturinagar 9842234521
Menu :
1:Add the records:
30
2:Search for a Record:
3:Update a record:
4: Display:
5: Exit:
Enter the choice: 5
31
8. Write a menu-driven Python program to manage a collection of countries using a
stack data structure. The program should support the following operations:
1. Insert (Push): Add a country to the top of the stack.
2. Delete (Pop): Remove the country from the top of the stack.
3. Peek: Display the country currently at the top of the stack without removing it.
4. Display: Show all countries currently in the stack, from top to bottom.
5. Exit: Terminate the program.
SOURCE CODE:
def insert(stk):
ans="y"
while ans=="y":
c=input("Enter country to be inserted into stack: ")
stk.append(c)
ans=input("Do you want to enter another country?y/n: ")
def delete(stk):
if stk==[]:
print("Stack underflow....Stack is empty")
else:
item=stk.pop()
print("Popped country is: ",item)
def peek(stk):
if stk==[]:
print("Stack underflow....Stack is empty")
else:
top=len(stk)-1
print("Topmost country in stack is:",stk[top])
32
def display(stk): #stack contents to be displayed in the reverse order.
if stk==[]:
print("Stack empty")
else:
top=len(stk)-1
print(stk[top],"<-Top")
for i in range(top-1,-1,-1):
print(stk[i])
print("Empty Stack")
#main segment
stk=[]
ans="y"
while ans.lower()=="y":
print("\n Menu:")
print("1. To insert countries into stack")
print("2. To delete country name from stack")
print("3. To peek stack")
print("4. To display stack")
print("5. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
insert(stk)
elif ch==2:
delete(stk)
elif ch==3:
peek(stk)
33
else:
display(stk)
ans=input("Do you want to continue? y/n: ")
OUTPUT:
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 1
Enter country to be inserted into stack: China
Do you want to enter another country?y/n: y
Enter country to be inserted into stack: India
Do you want to enter another country?y/n: n
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 4
India <-Top
China
34
Empty Stack
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 3
Topmost country in stack is: India
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 2
Popped country is: India
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
35
4. To display stack
5. Exit
Enter your choice: 2
Popped country is: China
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 2
Stack underflow....Stack is empty
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 3
Stack underflow....Stack is empty
Do you want to continue? y/n: y
36
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 4
Stack empty
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
4. To display stack
5. Exit
Enter your choice: 1
Enter country to be inserted into stack: Nepal
Do you want to enter another country?y/n: y
Enter country to be inserted into stack: Bangladesh
Do you want to enter another country?y/n: n
Do you want to continue? y/n: y
Menu:
1. To insert countries into stack
2. To delete country name from stack
3. To peek stack
37
4. To display stack
5. Exit
Enter your choice: 4
Bangladesh <-Top
Nepal
Empty Stack
Do you want to continue? y/n:
38
9.Write a menu driven Python program to implement the operations insert, delete,
peek and display on stack containing member details as given in the following
definition of members:
MemberNo integer
MemberName String
Age integer
SOURCE CODE:
def insert(stk):
ans="yes"
while ans.lower()=="yes":
mno=int(input("Enter the member no: "))
mname=input("Enter the member name: ")
age=int(input("Enter the member age: "))
stk.append([mno,mname,age])
ans=input("Do you want to enter another member?yes/no: ")
def delete(stk):
if stk==[]:
print("Stack underflow....Stack is empty")
else:
item=stk.pop()
print("Popped member is: ",item)
def peek(stk):
if stk==[]:
print("Stack underflow....Stack is empty")
else:
top=len(stk)-1
print("Topmost Member in stack is:",stk[top])
39
print(stk[top],"<-Top")
for i in range(top-1,-1,-1):
print(stk[i])
print("Empty Stack")
#main segment
stk=[]
ans="y"
while ans.lower()=="y":
print("\n Menu:")
print("1. PUSH")
print("2. POP")
print("3. PEEK")
print("4. DISPLAY")
print("5. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
insert(stk)
elif ch==2:
delete(stk)
elif ch==3:
peek(stk)
else:
display(stk)
ans=input("Do you want to continue the stack operations? y/n: ")
OUTPUT:
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 1
Enter the member no: 101
Enter the member name: Deeraj
Enter the member age: 45
Do you want to enter another member?yes/no: yes
Enter the member no: 202
Enter the member name: Vidya
Enter the member age: 25
40
Do you want to enter another member?yes/no: no
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 4
[202, 'Vidya', 25] <-Top
[101, 'Deeraj', 45]
Empty Stack
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 3
Topmost Member in stack is: [202, 'Vidya', 25]
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 2
Popped member is: [202, 'Vidya', 25]
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
41
5. Exit
Enter your choice: 1
Enter the member no: 503
Enter the member name: Hari
Enter the member age: 32
Do you want to enter another member?yes/no: no
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 4
[503, 'Hari', 32] <-Top
[101, 'Deeraj', 45]
Empty Stack
Do you want to continue the stack operations? y/n: n
42
10. Write a Python Program to implement a Stack for the book details (bookno,
bookname). That is, each item node of the stack contains two types of information- a
book number and its name. Implement all the operations of Stack (push, pop, peek,
display stack).
SOURCE CODE:
#contents are stored in the form of a dictionary
def insert(stk):
ans="yes"
while ans.lower()=="yes":
bno=int(input("Enter the Book no: "))
bname=input("Enter the Book name: ")
stk.append({bno:bname})
ans=input("Do you want to enter another book detail?yes/no: ")
def delete(stk):
if stk==[]:
print("Stack underflow....Stack is empty")
else:
item=stk.pop()
print("Popped Book is: ",item)
def peek(stk):
if stk==[]:
print("Stack underflow....Stack is empty")
else:
top=len(stk)-1
print("Topmost Book detail in stack is:",stk[top])
43
def display(stk): #stack contents to be displayed in the reverse order.
if stk==[]:
print("Stack empty")
else:
top=len(stk)-1
print(stk[top],"<-Top")
for i in range(top-1,-1,-1):
print(stk[i])
print("Empty Stack")
#main segment
stk=[]
ans="y"
while ans.lower()=="y":
print("\n Menu:")
print("1. PUSH")
print("2. POP")
print("3. PEEK")
print("4. DISPLAY")
print("5. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
insert(stk)
elif ch==2:
delete(stk)
elif ch==3:
peek(stk)
else:
44
display(stk)
ans=input("Do you want to continue the stack operations? y/n: ")
OUTPUT:
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 4
Stack empty
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 1
Enter the Book no: 101
Enter the Book name: Python programming
Do you want to enter another book detail?yes/no: yes
Enter the Book no: 102
Enter the Book name: C++
Do you want to enter another book detail?yes/no: no
45
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 4
{102: 'C++'} <-Top
{101: 'Python programming'}
Empty Stack
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 3
Topmost Book detail in stack is: {102: 'C++'}
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
46
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 2
Popped Book is: {102: 'C++'}
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 2
Popped Book is: {101: 'Python programming'}
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 4
Stack empty
Do you want to continue the stack operations? y/n: y
47
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 2
Stack underflow....Stack is empty
Do you want to continue the stack operations? y/n: y
Menu:
1. PUSH
2. POP
3. PEEK
4. DISPLAY
5. Exit
Enter your choice: 3
Stack underflow....Stack is empty
Do you want to continue the stack operations? y/n: n
48
11.Write a menu driven program to solve the following problems:
i) Write a program in Python to input 5 words and push them one by one into a list
named All.
The program should then use the function PushNV(N) to create a stack of words in the
list NoVowel so that it stores only those words which do not have any vowel present
in it, from the list All. Thereafter, pop each word from the list NoVowel and display
the popped word. When the stack is empty, display the message “Empty Stack”.
For Example:
If the words accepted and pushed onto the list All are:
[‘Dry’, ‘Like’,’ Rhythm’, ‘Work’, ‘Gym’]
Then the stack NoVowelshould store:
[‘Dry’, Rhythm’, ‘Gym’]
And the output should be displayed as :
Gym Rhythm Dry Empty Stack
ii) Write a program in Python to input 5 integers and push them one by one into a list
named Allvalues.
The program should then use the function ADD3_5(N) to create a stack of values in
the list named only3_5, so that it stores only those values that are divisible 3 or 5,
from the list Allvalues. Thereafter, pop each number from the list only3_5 and
display the popped number. When the stack is empty, display the message “Empty
Stack”.
For Example:
If the integers accepted and pushed onto the list Allvalues are:
[5,62,33,22,55]
Then the stack only3_5 should store:
[5,33,55]
And the output should be displayed as :
49
55 33 5 EmptyStack
SOURCE CODE:
def CreateALLlist(): #Creates the main list
#Create 5 words list
ALL=[]
for i in range(5):
word=input("Enter a word: ")
ALL.append(word)
print("ALL list is created")
50
print("NoVowel list contents are:")
print(NoVowel)
#Calls the pop() method to remove all the elements from NoVowel list
pop(NoVowel)
#Removes all the elements from NoVowel list and prints in reverse order, since
stack follows LIFO:
def pop(NoVowel) :
if NoVowel==[]:
print("Stack empty")
else:
print("The Stack contents are: ")
top=len(NoVowel)-1
while top>=0:
item=NoVowel.pop()
print(item,end= ' ' )
top-=1
else:
print("Empty Stack")
51
print(Allvalues)
#call PushNV() function
Push3_5(Allvalues)
52
print("Empty Stack")
#main segment
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. VOWEL BASED QUESTION")
print("2. NUMBER BASED QUESTION")
print("3. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
CreateALLlist()
elif ch==2:
CreateNumbersList()
else: #if else
break
ans=input("Do you want to continue the operations? yes/no: ")
OUTPUT:
Menu:
1. VOWEL BASED QUESTION
2. NUMBER BASED QUESTION
3. Exit
Enter your choice: 1
Enter a word: DRY
Enter a word: LIKE
Enter a word: RYTHYM
Enter a word: WORK
Enter a word: GYM
ALL list is created
53
NoVowel list contents are:
['DRY', 'RYTHYM', 'GYM']
The Stack contents are:
GYM RYTHYM DRY Empty Stack
Do you want to continue the operations? yes/no: YES
Menu:
1. VOWEL BASED QUESTION
2. NUMBER BASED QUESTION
3. Exit
Enter your choice: 2
Enter a Number: 45
Enter a Number: 34
Enter a Number: 67
Enter a Number: 89
Enter a Number: 97
Allvalues list is created
[45, 34, 67, 89, 97]
The Only3_5 List contents are :
[45]
The Stack contents are:
45 Empty Stack
Do you want to continue the operations? yes/no: no
54
12. Write a Menu based Python program that has two functions which can:
(i) Accept a string and calculate the number of upper case letters, lower case letters
and number of digits.
Sample String : 'The quick Brown Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
No. of digits= 0
(ii) Accept a hyphen-separated sequence of words as input and prints the words in a
hyphen-separated sequence after sorting them alphabetically.
Input:
Enter hypenseperated words: green-red-black-white
Exptected Output:
Hypen seperated sorted words:
black-green-red-white
SOURCE CODE:
def count(s):
uppercount=lowercount=digitscount=0
for ch in s:
if ch.isupper():
uppercount+=1
elif ch.islower():
lowercount+=1
elif ch.isdigit():
digitscount+=1
def hypen(s):
55
s1=''
list=s.split('-') #splits the sentence to list of words
list.sort() #Sorts the list in the ascending order of words
print(" Hypen Seperated sorted words :")
s1='-'.join(list)
print(s1)
#main segment
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Count the no of vowels, upper case, lowercase and digits")
print("2. Hypen Seperated sequence of words")
print("3. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
str=input(" Enter a sentence")
count(str)
elif ch==2:
str=input(" Accept the hypen seperated words")
hypen(str)
else:
break
ans=input("Do you want to continue the operations? yes/no: ")
56
OUTPUT:
Menu:
1. Count the no of vowels, upper case, lowercase and digits
2. Hypen Seperated sequence of words
3. Exit
Enter your choice: 2
Accept the hypen seperated wordsred-green-black-violet
Hypen Seperated sorted words :
black-green-red-violet
Do you want to continue the operations? yes/no: yes
Menu:
1. Count the no of vowels, upper case, lowercase and digits
2. Hypen Seperated sequence of words
3. Exit
Enter your choice: 1
Enter a sentencethis is a line of text123
The no. of upper case characters = 0
The no. of lower case characters = 17
The no. of digits = 3
Do you want to continue the operations? yes/no: no
57
13. Write a menu driven Python program (Use Functions):
(i) Write a user defined function showgrades(S) which takes the dictionary S as
an argument. The dictionary, S contains Name: [Eng: Math, Science] as key:
value pairs. The function displays the corresponding grade obtained by the
students according to the following grading rules:
Average of Eng, Math, Grade
Science
>=90 A
<90 but >60 B
<60 C
58
SOURCE CODE:
def grade(d): #Calculating the grade of the student
print("Students' Grades :")
for key in d:
averagemarks=sum(d[key])/3
if averagemarks>=90:
print(key, ' - A Grade')
elif averagemarks>60 and averagemarks<90:
print(key, ' - B Grade')
else:
print(key, ' - B Grade')
59
ch=int(input("Enter your choice: "))
if ch==1:
print("Creating the dictionary of students details")
ans='yes'
d={}
while ans.lower()=='yes':
name=input("Enter the student name")
marks=eval(input("Enter 3 subject marks in the form of list"))
d[name]=marks
ans=input("Do you want to enter more student data in the dictionary? yes/no")
print("The Dictionary contents are: ")
print(d)
grade(d)
elif ch==2:
str=input(" Enter a string value:")
n=int(input("Enter the position number where the character is to be replace by
'-'"))
print("New string = ",Puzzle(str,n))
else:
break
ans=input("Do you want to continue the operations? yes/no: ")
60
OUTPUT:
Menu:
1. Calculating the grade of the student
2. String based program
3. Exit
Enter your choice: 1
Creating the dictionary of students details
Enter the student nameSachin
Enter 3 subject marks in the form of list[45,56,67]
Do you want to enter more student data in the dictionary? yes/noyes
Enter the student nameVarun
Enter 3 subject marks in the form of list[89,90,90]
Do you want to enter more student data in the dictionary? yes/noyes
Enter the student nameRithvik
Enter 3 subject marks in the form of list[78,45,39]
Do you want to enter more student data in the dictionary? yes/nono
The Dictionary contents are:
{'Sachin': [45, 56, 67], 'Varun': [89, 90, 90], 'Rithvik': [78, 45, 39]}
Students' Grades :
Sachin - B Grade
Varun - B Grade
Rithvik - B Grade
Do you want to continue the operations? yes/no: yes
Menu:
1. Calculating the grade of the student
2. String based program
3. Exit
61
Enter your choice: 2
Enter a string value:TELEVISION
Enter the position number where the character is to be replace by '-'3
New string = TE_EV_SI_N
Do you want to continue the operations? yes/no: NO
62
14. Write a menu driven Python program (Use functions):
(i) Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES
as an argument and displays the names (in uppercase) of the places whose names
are longer than 5 characters.
For example, Consider the following dictionary:
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"}
The output should be:
LONDON
NEW YORK
(ii) Write a function, lenWords(STRING), that takes a string as an argument and
returns a tuple containing length of each word of a string.
For example, if the string is "Come let us have some fun", the tuple will have
(4, 3, 2, 4, 4, 3).
SOURCE CODE:
def lenWords(STRING):
list=STRING.split()
#Create an empty tuple
t=()
63
for word in list:
t+=(len(word),) #tuple concat- adding the length of each word in the tuple
return(t) #outside the for loop
#main segment
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Display the place names whose length is above 5")
print("2. Calculate the length of each word of the given sentence")
print("3. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
print("Creating the dictionary which contains places as elements")
ans='yes'
d={}
while ans.lower()=='yes':
key=int(input("Enter a number as key"))
place=input("Enter a place name")
d[key]=place
ans=input("Do you want to enter more places in the dictionary? yes/no")
print("The Dictionary contents are: ")
print(d)
countNow(d)
elif ch==2:
str=input(" Enter a string value:")
tuple=lenWords(str)
64
print("The length of each word of the given string =" , tuple)
else:
break
ans=input("Do you want to continue the operations? yes/no: ")
OUTPUT:
Menu:
1. Display the place names whose length is above 5
2. Calculate the length of each word of the given sentence
3. Exit
Enter your choice: 1
Creating the dictionary which contains places as elements
Enter a number as key1
Enter a place nameDelhi
Do you want to enter more places in the dictionary? yes/noyes
Enter a number as key2
Enter a place nameLondon
Do you want to enter more places in the dictionary? yes/noyes
Enter a number as key3
Enter a place nameParis
Do you want to enter more places in the dictionary? yes/noyes
Enter a number as key4
Enter a place nameNew York
Do you want to enter more places in the dictionary? yes/noyes
Enter a number as key5
Enter a place nameDoha
Do you want to enter more places in the dictionary? yes/nono
The Dictionary contents are:
{1: 'Delhi', 2: 'London', 3: 'Paris', 4: 'New York', 5: 'Doha'}
Places whose length is longer than 5 characters :
LONDON
NEW YORK
Do you want to continue the operations? yes/no: yes
65
Menu:
1. Display the place names whose length is above 5
2. Calculate the length of each word of the given sentence
3. Exit
Enter your choice: 2
Enter a string value:Come let us have some fun
The length of each word of the given string = (4, 3, 2, 4, 4, 3)
Do you want to continue the operations? yes/no: no
66
15. Write a menu driven Python program (Use functions):
(i) To create a dictionary with roll number and names of 5 students. Search for a given
roll number and display the name, if not found display appropriate message.
(ii) Write a random number generator that generates random numbers between 1 and
6 (simulates a dice roll).
SOURCE CODE:
67
break
else:
print("The rollno does not exist in the dictionary")
print("Search Unsuccessful")
def generaterandom():
import random
ans='yes'
print("Simualtes a dice")
while ans.lower()=='yes':
#randint generates values from 0 to 6(both 0 and 6 are inclusive)
no=random.randint(0,6)
print(no)
ans=input("Do you want to continue? yes/no: ")
#main segment
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Search for a roll no in the Dictionary")
print("2. Random no generator that simulates a dice")
print("3. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
d={}
Create(d)
elif ch==2:
68
generaterandom()
else:
break
ans=input("Do you want to continue the operations? yes/no: ")
69
Output:
Menu:
1. Search for a roll no in the Dictionary
2. Random no generator that simulates a dice
3. Exit
Enter your choice: 1
Enter a rollno as key101
Enter a student nameVarun
Do you want to enter more student names in the dictionary? yes/noyes
Enter a rollno as key102
Enter a student nameyashika
Do you want to enter more student names in the dictionary? yes/nono
The Dictionary contents are:
{101: 'Varun', 102: 'yashika'}
Inside Search method: {101: 'Varun', 102: 'yashika'}
Enter the rollno you want to search in the dictionary: 102
Search Successful
The student's details are:
102 yashika
Do you want to continue the operations? yes/no: yes
Menu:
1. Search for a roll no in the Dictionary
2. Random no generator that simulates a dice
3. Exit
Enter your choice: 1
Enter a rollno as key101
70
Enter a student nameyash
Do you want to enter more student names in the dictionary? yes/noyes
Enter a rollno as key102
Enter a student nameJanya
Do you want to enter more student names in the dictionary? yes/nono
The Dictionary contents are:
{101: 'yash', 102: 'Janya'}
Inside Search method: {101: 'yash', 102: 'Janya'}
Enter the rollno you want to search in the dictionary: 109
The rollno does not exist in the dictionary
Search Unsuccessful
Do you want to continue the operations? yes/no: yes
Menu:
1. Search for a roll no in the Dictionary
2. Random no generator that simulates a dice
3. Exit
Enter your choice: 2
Simualtes a dice
5
Do you want to continue? yes/no: yes
6
Do you want to continue? yes/no: no
Do you want to continue the operations? yes/no: no
71
SQL PROGRAMS
16. Given below are the tables for a database Library.
Table: Books
Bookid Bname Authorname Publishe Price Type Quantit
rs y
C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5
F0001 The Tears William First Publ 650 Fiction 20
Hopkins
T0001 My First C++ Brain and EPB 350 Text 10
Brooke
T0002 Python A W Rossaine TDH 350 Text 15
F0002 Thunderbolts Anna Roberts First Publ 750 Fiction 50
Table: Issued
Bookid Quantity_issue
d
C0001 4
F0001 5
T0001 2
Write SQL Queries for the following:
a) To show the Book name, Author name and Price of books of First Publ.
Publishers.
b) Change the price data type to float.
c) To display the names and prices of books in ascending order of their price.
d) To increase the price of all books of EPB publishers by Rs.50
e) To display the Bookid, Book name and Quantity issued of all books which have
been issued.
Source Code:
72
mysql> create table Books (bookid varchar(8) , bname
varchar(25),Authorname varchar(25), publishers varchar(25), price float,
type varchar(20), quantity int);
Query OK, 0 rows affected (0.06 sec)
mysql> desc books;
73
#Creating Issued Table:
mysql> create table Issued(Bookid varchar(8), Quanitiy_issued int);
Query OK, 0 rows affected (0.04 sec)
74
#To display the records of Issued Table:
c) To display the names and prices of books in ascending order of their price.
75
d) To increase the price of all books of EPB publishers by Rs.50.
e) To display the Bookid, Book name and Quantity issued of all books which have been
issued.
76
17. In a Company database, there are two tables as given below:
Table: Employee
Empid Ename Sales jobid
E1 Sumit Sinha 1100000 102
E2 Vijay Singh 1300000 101
E3 Ajay Rajpal 1400000 103
E4 Mohit Ramnani 1250000 102
E5 Shailaja Singh 1450000 103
Table: Job
Jobid Jobtitle Salary
101 President 200000
102 Vice President 125000
103 Administration 80000
Assistant
104 Accounting Manager 70000
105 Accountant 65000
106 Sales Manager 80000
Write SQL Queries for the following:
a) To display employee ids, names of employees, job ids with corresponding job
titles.
b) To display the names of the employees, sales and corresponding job titles who
have achieved sales more than 1300000.
c) To display names and corresponding job titles of those employees who have
‘Singh’ (anywhere) in their names.
d) Write SQL command to change the jobid to 104 of the Employee with ID as E4 in
the table ‘Employee’.
77
e) Write SQL command to delete the employee record whose name is ‘Ajay Rajpal’
in the Employee table.
Source Code:
#Creating tables:
mysql> create table job(jobid integer, jobtitle varchar(30), salary integer,
primary key(jobid));
Query OK, 0 rows affected (0.04 sec)
79
mysql> insert into employee values('E2', 'Vijay Singh', 1300000,101);
Query OK, 1 row affected (0.01 sec)
80
a) To display employee ids, names of employees, job ids with corresponding job
titles.
b) To display the names of the employees, sales and corresponding job titles who
have achieved sales more than 1300000.
c) To display names and corresponding job titles of those employees who have
‘Singh’ (anywhere) in their names.
81
d) Write SQL command to change the jobid to 104 of the Employee with ID as E4 in the
table ‘Employee’.
e) Write SQL command to delete the employee record whose name is ‘Ajay Rajpal’ in
the Employee table.
82
18. Write SQL command for the queries a) to e) based on the tables company and
customer.
Table: Company
CID CompanyName City ProductName
111 Sony Delhi TV
222 Nokia Mumbai Mobile
333 Onida Delhi TV
444 Sony Mumbai Mobile
555 BlackBerry Bangalore Mobile
666 Dell Bangalore Mobile
Table: Customer
Custid CustName Price Qty CID
101 Rohan Sharma 70000 20 222
102 Deepak Kumar 50000 10 666
103 Mohan Kumar 30000 5 111
104 Sahil Bansal 35000 3 333
105 Neha Soni 25000 7 444
106 Sonal Aggarwal 20000 5 333
107 Arjun Singh 50000 15 666
a) To display the company names which are having price less than 30000.
b) To display the names of companies in reverse alphabetical order.
c) To increase the price by Rs.1000 for those customers whose names start with ‘S’.
d) To add one more column totalprice with decimal(10,2) to the table customer.
e) Display the minimum, maximum and average price of the product from the
customer table.
83
SOURCE CODE:
mysql> create table company(cid integer primary key, companyname
varchar(25), city varchar(20), productname varchar(25));
Query OK, 0 rows affected (0.05 sec)
84
mysql> insert into customer values(101,'Rohan Sharma',70000,20,222);
Query OK, 1 row affected (0.02 sec)
85
Write SQL Queries for the following:
a) To display the company names which are having price less than 30000.
mysql> select companyname from company natural join customer where price
<30000;
+-------------+
| companyname |
+-------------+
| Sony |
| Onida |
+-------------+
2 rows in set (0.00 sec)
86
b) To display the names of companies in reverse alphabetical order.
c) To increase the price by Rs.1000 for those customers whose names start with ‘S’.
d) To add one more column totalprice with decimal(10,2) to the table customer.
MySQL> alter table customer add totalprice decimal(10,2);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
87
e) Display the minimum, maximum and average price of the product from the
customer table.
88
19. Write SQL commands for the queries a) to e) based on the tables ‘Watches’ and
‘Sale’ given below.
Table: Watches
Watchid Watchname Price Type Qty_store
W001 HighTime 10000 Unisex 100
W002 LifeTime 15000 Ladies 150
W003 Wave 20000 Gents 200
W004 HighFashion 7000 Unisex 250
W005 GoldenTime 25000 Gents 100
Table: Sale
Watchid Qty_sold Quarter
W001 10 1
W003 5 1
W002 20 2
W003 10 2
W001 15 3
W002 20 3
W005 10 3
W003 15 4
Write SQL Queries for the following:
a) Display all the details of those watches whose name ends with ‘Time’.
b) Display watch’s name and price of those watches which have price range in
between 5000 to 15000.
c) Display total quantity in store of Unisex type watches.
d) Display watch name and their quantity sold in first quarter.
e) Display Watchid, Watch name, type and quantity sold from the tables watches
and sale.
89
Source code:
#Creating Tables:
mysql> create table watches(watchid varchar(6), watchname varchar(25),p
rice int,type varchar(15),Qty_store int,primary key(watchid));
Query OK, 0 rows affected (0.04 sec)
90
mysql> insert into sale values('W001',10,1);
Query OK, 1 row affected (0.01 sec)
91
Write SQL Queries for the following:
a) Display all the details of those watches whose name ends with ‘Time’.
b) Display watch’s name and price of those watches which have price range in
between 5000 to 15000.
e) Display Watchid, Watch name, type and quantity sold from the tables watches and
sale.(mentioned both equi join and natural join)
20. Write SQL queries for (a) to (e) which are based on the following tables Account
and Transact.
93
Table: Account
ANO ANAME ADDRESS
101 Nirja Singh Bangalore
102 Rohan Gupta Chennai
103 Abdul Hyderabad
104 Rishabh Jain Chennai
105 Simran Kaur Chandigarh
Table: Transact
TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-
21
T002 103 3000 Deposit 2017-06-
01
T003 102 2000 Withdraw 2020-05-
12
T004 103 1000 Deposit 2020-10-
22
T005 102 12000 Deposit 2017-11-
06
Write SQL Queries for the following:
a) Display details of all transactions of Type Withdrawfrom Transact table. While
displaying TRNO and ANO, mention the column headings as ‘Transaction
Number’ and ’Account Number’ respectively.
b) Display ANO and Amount of all Deposit and Withdrawals done in the month of May
2020 from table Transact.
94
c) Display first date of transaction (DOT) from table Transact for Account having ANO
as 102.
d) Display ANO, ANAME, AMOUNT and DOT of those persons from Account and
Transact table who have done transaction less than or equal to 3000.
e) Display the details of Account table based on Account holder names in Ascending
order.
f) Write a SQL query to count the number of customers from each city in the account
table. Display the city and the corresponding count of customers, sorted by the
city name.
g) Write a SQL query to calculate the total amount transacted (both deposit and
withdrawal) for each account number (ano).
SOURCE CODE:
mysql> create table account(ano int primary key, aname varchar(25), addr
ess varchar(50));
Query OK, 0 rows affected (0.04 sec)
95
mysql> insert into account values(105,'Simran Kaur','Chandigarh');
Query OK, 1 row affected (0.01 sec)
96
a) Display details of all transactions of Type Withdraw from Transact table. While
displaying TRNO and ANO, mention the column headings as ‘Transaction Number’
and ’Account Number’ respectively.
h) Display ANO and Amount of all Deposit and Withdrawals done in the month of May
2020 from table Transact.
c) Display first date of transaction (DOT) from table Transact for Account having ANO
as 102.
97
d) Display ANO, ANAME, AMOUNT and DOT of those persons from Account and
Transact table who have done transaction less than or equal to 3000.
#Natural join
#Equi join:
98
e) Display the details of Account table based on Account holder names in Ascending
order.
f) Write a SQL query to count the number of customers from each city in the account
table. Display the city and the corresponding count of customers, sorted by the city
name.
SELECT address, COUNT(*) AS customer_count
FROM account
GROUP BY address
ORDER BY address;
99
g) Write a SQL query to calculate the total amount transacted (both deposit and
withdrawal) for each account number (ano).
100
INTERFACE PYTHON WITH MYSQL
21. Create a table employee1 with the following structure:
Column Datatyp Size/Constraint
name e
Empid Integer Primary key
Ename Varchar 25, not null
Job Varchar 20, not null
Salary integer Not null
Use Python with MySQL interface to do the following:
a) Insert a record in the employee1 table.
b) Change salary of the employee whose name is ‘Vijay’.
c) Select the records from the employee1 table whose job is Manager.
SOURCE CODE:
import mysql.connector as sql
def Create():
query="create table if not exists employee1(empid int primary key, ename
varchar(25), job varchar(20), salary int not null)"
mycursor.execute(query)
conobj.commit()
print("Table created")
def InsertRecord():
eid=int(input("Enter the Employee Id"))
name=input("Enter Employee Name")
job=input("Enter the Job name")
salary=int(input("Enter the salary"))
query="insert into employee1 values({},'{}','{}',{})".format(eid,name,job,salary)
101
mycursor.execute(query)
conobj.commit()
print("One Record inserted")
def ChangeSalary():
name=input("Enter the Employee Name")
salary=int(input("Enter the new salary"))
query="update employee1 set salary={} where ename='{}'".format(salary,name)
mycursor.execute(query)
print("The record is updated")
conobj.commit()
def Display():
query="select * from employee1"
mycursor.execute(query)
data=mycursor.fetchall()
if data==[]:
print("No record found in the table")
else:
print("The Employee Table contents: ")
for rec in data:
print(rec[0],rec[1],rec[2],rec[3])
#main segment
conobj=sql.connect(host='localhost', user='root', passwd='psbe',database='school')
mycursor=conobj.cursor()
ans="yes"
102
while ans.lower()=="yes":
print("\n Menu:")
print("1. Create Table")
print("2. Insert a Record")
print("3. Change the Salary of the Employee")
print("4. Display the Manager Record")
print("5. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
Create()
elif ch==2:
InsertRecord()
elif ch==3:
ChangeSalary()
elif ch==4:
Display()
else:
break
OUTPUT:
Menu:
1. Create Table
2. Insert a Record
3. Change the Salary of the Employee
4. Display the Manager Record
103
5. Exit
Enter your choice: 1
Table created
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Change the Salary of the Employee
4. Display the Manager Record
5. Exit
Enter your choice: 2
Enter the Employee Id102
Enter Employee NameVarun
Enter the Job nameManager
Enter the salary100000
One Record inserted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Change the Salary of the Employee
4. Display the Manager Record
5. Exit
Enter your choice: 2
Enter the Employee Id103
Enter Employee NameVijay
104
Enter the Job nameAdministrator
Enter the salary150000
One Record inserted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Change the Salary of the Employee
4. Display the Manager Record
5. Exit
Enter your choice: 3
Enter the Employee NameVijay
Enter the new salary170000
The record is updated
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Change the Salary of the Employee
4. Display the Manager Record
5. Exit
Enter your choice: 4
The Employee Table contents:
102 Varun Manager 100000
103 Vijay Administrator 170000
Do you want to continue the operations? yes/no:No
105
22. Create a table Inventory with the following structure:
PCode Pname Price QTY
Category (Product (Product (Price of the (Number of
Code) name) Product) items in stock)
Beverage B163 Best Juice 10 10
Snack S968 Yummy 20 40
Noodle N042 WOW 20 20
Beverage B678 Fresh tea 25 80
def InsertRecord():
category=input("Enter Product category : ")
pcode=input("Enter the Product Code : ")
name=input("Enter the Product Name: ")
price=int(input("Enter the Price: "))
106
quantity=int(input("Enter the number of items in Stock "))
query="insert into inventory values('{}','{}','{}',{},
{})".format(category,pcode,name,price,quantity)
mycursor.execute(query)
conobj.commit()
print("One Record inserted")
def Delete():
pname='Wow'
query="delete from inventory where pname ='{}'".format(pname)
mycursor.execute(query)
print("The record is deleted")
conobj.commit()
def DisplaySelected():
query="select * from inventory where price>=20"
mycursor.execute(query)
data=mycursor.fetchall()
if data==[]:
print("No record found in the table")
else:
print("The InventoryTable contents: ")
for rec in data:
print(rec[0],rec[1],rec[2],rec[3],rec[4])
def DisplayAll():
query="select * from inventory "
107
mycursor.execute(query)
data=mycursor.fetchall()
if data==[]:
print("No record found in the table")
else:
print("The InventoryTable contents: ")
for rec in data:
print(rec[0],rec[1],rec[2],rec[3],rec[4])
#main segment
conobj=sql.connect(host='localhost', user='root',
passwd='psbe',database='school')
mycursor=conobj.cursor()
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Create Table")
print("2. Insert a Record")
print("3. Delete the record")
print("4. Display the selected Records")
print("5. Display All Records")
print("6. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
Create()
elif ch==2:
InsertRecord()
108
elif ch==3:
Delete()
elif ch==4:
DisplaySelected()
elif ch==5:
DisplayAll()
else:
break
OUTPUT:
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 1
Table created
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
109
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 5
No record found in the table
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 2
Enter Product category : Beverage
Enter the Product Code : B163
Enter the Product Name: Best Juice
Enter the Price: 10
Enter the number of items in Stock 10
One Record inserted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
110
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 2
Enter Product category : Snack
Enter the Product Code : S968
Enter the Product Name: Yummy
Enter the Price: 20
Enter the number of items in Stock 40
One Record inserted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 2
Enter Product category : Noodle
Enter the Product Code : N042
Enter the Product Name: Wow
Enter the Price: 20
Enter the number of items in Stock 20
One Record inserted
Do you want to continue the operations? yes/no: yes
111
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 2
Enter Product category : Beverage
Enter the Product Code : B678
Enter the Product Name: Fresh Tea
Enter the Price: 25
Enter the number of items in Stock 80
One Record inserted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 5
The InventoryTable contents:
Beverage B163 Best Juice 10 10
112
Beverage B678 Fresh Tea 25 80
Noodle N042 Wow 20 20
Snack S968 Yummy 20 40
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 3
The record is deleted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 5
The InventoryTable contents:
Beverage B163 Best Juice 10 10
Beverage B678 Fresh Tea 25 80
113
Snack S968 Yummy 20 40
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Table
2. Insert a Record
3. Delete the record
4. Display the selected Records
5. Display All Records
6. Exit
Enter your choice: 4
The Inventory Table contents:
Beverage B678 Fresh Tea 25 80
Snack S968 Yummy 20 40
Do you want to continue the operations? yes/no: no
114
23. Use Python with MySQL interface to do the following:
a. Create a database Exam
b. Check whether the database is created or not.
c. Create table ‘Student’ inside the database ‘Exam’ with the following
description.
Column name Datatype Size/Constraint
Rollno Integer Size=3, Primary key
sname Varchar Size=25, not null
age integer Size=2
City Char Size=20
SOURCE CODE:
import mysql.connector as sql
def CreateDatabase():
query="create database if not exists Exam"
mycursor.execute(query)
conobj.commit()
print("Database Created")
def CheckDatabase():
databasename=input("Enter database name: ")
query="show databases like '{}'".format(databasename)
mycursor.execute(query)
data=mycursor.fetchone() #if no database exists, fetchone() returns None.
if data:
print("Database exists")
else: #if else
115
print("Data base does not exist")
def CreateTable():
query="Use exam"
mycursor.execute(query)
query="create table if not exists student(rollno int(3) primary key,sname
varchar(25) not null, age int(2), city char(20))"
mycursor.execute(query)
conobj.commit()
print("Table created")
#main segment
conobj=sql.connect(host='localhost', user='root', passwd='psbe')
mycursor=conobj.cursor()
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Create Database")
print("2. Check the existence of a Database")
print("3. Create Student table")
print("4. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
CreateDatabase()
elif ch==2:
CheckDatabase()
elif ch==3:
CreateTable()
116
else:
break
OUTPUT:
Menu:
1. Create Database
2. Check the existence of a Database
3. Create Student table
4. Exit
Enter your choice: 1
Database Created
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Database
2. Check the existence of a Database
3. Create Student table
4. Exit
Enter your choice: 2
Enter database name: exam
Database exists
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Database
2. Check the existence of a Database
3. Create Student table
4. Exit
Enter your choice: 3
Table created
Do you want to continue the operations? yes/no: no
117
24. Use Python with MySQL interface to do the following:
a) Create table ‘Student’ inside the database ‘Exam’ with the following description.
Column name Datatype Size/Constraint
Rollno Integer Size=3, Primary key
sname Varchar Size=25, not null
age integer Size=2
City Char Size=20
b) Add a new column mark in the above table with datatype integer with size 3.
c) Insert records in the above table as per user requirement.
SOURCE CODE:
def CreateTable():
query="create table if not exists student(rollno int(3) primary key,sname
varchar(25) not null, age int(2), city char(20))"
mycursor.execute(query)
conobj.commit()
print("Table created")
def AddMarkColumn():
try:
query="Alter table student add mark int(3)"
mycursor.execute(query)
conobj.commit()
except:
print("Marks column already created")
else:
print("Column added int the Student table")
118
def InsertRecord():
rno=int(input("Enter 3 digit rollno: "))
name=input("Enter Student name: ")
age=int(input("Enter the Student age: "))
city=input("Enter the city name: ")
query="insert into student (rollno,sname, age, city) values({},'{}',
{},'{}')".format(rno,name,age,city)
mycursor.execute(query)
conobj.commit()
print("One record is added in the Student table")
#main segment
conobj=sql.connect(host='localhost', user='root', passwd='psbe', database='Exam')
mycursor=conobj.cursor()
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Create Student Table")
print("2. Add the Mark Column")
print("3. Insert Records in the Student table")
print("4. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
CreateTable()
elif ch==2:
AddMarkColumn()
elif ch==3:
InsertRecord()
else:
break
119
OUTPUT:
Menu:
1. Create Student Table
2. Add the Mark Column
3. Insert Records in the Student table
4. Exit
Enter your choice: 1
Table created
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Add the Mark Column
3. Insert Records in the Student table
4. Exit
Enter your choice: 2
Column added int the Student table
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Add the Mark Column
3. Insert Records in the Student table
4. Exit
Enter your choice: 2
Marks column already created
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Add the Mark Column
3. Insert Records in the Student table
4. Exit
Enter your choice: 3
Enter 3 digit rollno: 101
Enter Student name: Sachin
Enter the Student age: 17
Enter the city name: Bangalore
One record is added in the Student table
Do you want to continue the operations? yes/no: yes
120
Menu:
1. Create Student Table
2. Add the Mark Column
3. Insert Records in the Student table
4. Exit
Enter your choice: 3
Enter 3 digit rollno: 103
Enter Student name: Rithvik
Enter the Student age: 17
Enter the city name: Coimbatore
One record is added in the Student table
Do you want to continue the operations? yes/no: no
121
25. Create table ‘Student’ inside the database ‘Exam’ with the following description.
Column name Datatype Size/Constraint
Rollno Integer Size=3, Primary key
sname Varchar Size=25, not null
age integer Size=2
City Char Size=20
mark integer Size=3
Insert 5 records in the above table
a. Display the records from the above table whose marks in the range of 80 to 95.
b. Change the student marks to 98 whose rollno is 103.
c. Delete the student record as per the rollno given by the user.
SOURCE CODE:
import mysql.connector as sql
def CreateTable():
query="create table if not exists student(rollno int(3) primary key,sname
varchar(25) not null, age int(2), city char(20),marks integer(3))"
mycursor.execute(query)
conobj.commit()
print("Table created")
122
query="insert into student (rollno,sname, age, city,marks) values({},'{}',
{},'{}',{})".format(rno,name,age,city,mark)
mycursor.execute(query)
conobj.commit()
print(i+1, "record is added in the Student table")
def ChangeMarks():
rno=103
newmarks=98
query="update student set marks={} where rollno={}".format(newmarks,rno)
mycursor.execute(query)
print("The record is updated")
conobj.commit()
def Delete():
rno=int(input("Enter the 3 digit rollno of the student"))
query="delete from student where rollno ={}".format(rno)
mycursor.execute(query)
print("The record is deleted")
conobj.commit()
def DisplaySelectedRecords():
query="select * from student where marks between 80 and 95"
mycursor.execute(query)
data=mycursor.fetchall()
#fetchall() will return [ ] if no records are returned #by the query
if data==[]:
123
print("No record found in the table")
else:
print("The Student details whose marks lies in the range of 80 to 95 : ")
for rec in data:
print(rec[0],rec[1],rec[2],rec[3],rec[4])
def DisplayAll():
query="select * from student "
mycursor.execute(query)
data=mycursor.fetchall()
if data==[]:
print("No record found in the table")
else:
print("The Student Table contents: ")
for rec in data:
print(rec[0],rec[1],rec[2],rec[3],rec[4])
#main segment
conobj=sql.connect(host='localhost', user='root', passwd='psbe', database='Exam')
mycursor=conobj.cursor()
ans="yes"
while ans.lower()=="yes":
print("\n Menu:")
print("1. Create Student Table")
print("2. Insert 5 records in the Student table")
print("3. Display the records from the above table whose marks in the range of 80 to
95")
124
print("4. Change the student marks to 98 whose rollno is 103.")
print("5. Delete the student record as per the rollno given by the user.")
print("6. Display Student Records anytime")
print("7. Exit ")
ch=int(input("Enter your choice: "))
if ch==1:
CreateTable()
elif ch==2:
InsertRecord()
elif ch==3:
DisplaySelectedRecords()
elif ch==4:
ChangeMarks()
elif ch==5:
Delete()
elif ch==6:
DisplayAll()
else:
break
OUTPUT:
Menu:
1. Create Student Table
2. Insert 5 records in the Student table
3. Display the records from the above table whose marks in the range of 80 to 95
125
4. Change the student marks to 98 whose rollno is 103.
5. Delete the student record as per the rollno given by the user.
6. Display Student Records anytime
7. Exit
Enter your choice: 1
Table created
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Insert 5 records in the Student table
3. Display the records from the above table whose marks in the range of 80 to 95
4. Change the student marks to 98 whose rollno is 103.
5. Delete the student record as per the rollno given by the user.
6. Display Student Records anytime
7. Exit
Enter your choice: 6
The Student Table contents:
101 Sachin 17 Bangalore 90
102 Yatra 17 Coimbatore 80
103 Rithvee 17 Coimbatore 98
104 Aram 18 Bangalore 67
105 Nivedita 17 Coimbatore 55
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
126
2. Insert 5 records in the Student table
3. Display the records from the above table whose marks in the range of 80 to 95
4. Change the student marks to 98 whose rollno is 103.
5. Delete the student record as per the rollno given by the user.
6. Display Student Records anytime
7. Exit
Enter your choice: 3
The Student details whose marks lies in the range of 80 to 95 :
101 Sachin 17 Bangalore 90
102 Yatra 17 Coimbatore 80
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Insert 5 records in the Student table
3. Display the records from the above table whose marks in the range of 80 to 95
4. Change the student marks to 98 whose rollno is 103.
5. Delete the student record as per the rollno given by the user.
6. Display Student Records anytime
7. Exit
Enter your choice: 4
The record is updated
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Insert 5 records in the Student table
127
3. Display the records from the above table whose marks in the range of 80 to 95
4. Change the student marks to 98 whose rollno is 103.
5. Delete the student record as per the rollno given by the user.
6. Display Student Records anytime
7. Exit
Enter your choice: 5
Enter the 3 digit rollno of the student102
The record is deleted
Do you want to continue the operations? yes/no: yes
Menu:
1. Create Student Table
2. Insert 5 records in the Student table
3. Display the records from the above table whose marks in the range of 80 to 95
4. Change the student marks to 98 whose rollno is 103.
5. Delete the student record as per the rollno given by the user.
6. Display Student Records anytime
7. Exit
Enter your choice: 6
The Student Table contents:
101 Sachin 17 Bangalore 90
103 Rithvee 17 Coimbatore 98
104 Aram 18 Bangalore 67
105 Nivedita 17 Coimbatore 55
Do you want to continue the operations? yes/no:no
128