0% found this document useful (0 votes)
7 views20 pages

Computer Study Material Programs

The document contains multiple Python programming exercises, including generating Fibonacci series, calculating factorials and sums, computing simple and compound interest, and analyzing text files for character counts. It also includes programs for creating and reading binary files with student records, sorting lists using bubble, selection, and insertion sort methods. Each section provides code snippets, expected outputs, and user interaction prompts.
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)
7 views20 pages

Computer Study Material Programs

The document contains multiple Python programming exercises, including generating Fibonacci series, calculating factorials and sums, computing simple and compound interest, and analyzing text files for character counts. It also includes programs for creating and reading binary files with student records, sorting lists using bubble, selection, and insertion sort methods. Each section provides code snippets, expected outputs, and user interaction prompts.
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

PARTA

PYTHO N
a
A 1. Write a python program using function to print fibonacci series up to n numbers

#Fibonacci numbers

def fibo(n):

nl =O

n2= 1

next_number = n2

count=2

print(nl ," ",n2,en d=" ")

while count<n:

print(next_number,end=" ")

count +=1

n 1, n2 = n2, next_number

next_number = n 1 + n2
n = int(input("enter the Limit"))

fibo(n)

print()

OUTPUT:
enter the Limit 10

0 I I 2 3 5 8 13 21 34 55 89
I At• Write a Menu driven program
in python to find factorial, and sum of
natural NumbefS using a function
#python program to find factorial of giv
en number and Sum of natural number
s
def fact(n):
return 1 if (n 1 or n =0 ) else n• fact (n-1 );
defsutn (n):
return Oif (n= O) else n+sum(n-
1);
nUOl == int(input("Enter any nu mb er: "))

print(" 1-Tofind the factorial, 2-T


o find the sum 3-Exit")
opt==int(input("Enter the option 1-3
: "))
if(opt=l):
print("Factorial of' ,nu m, "is : ",sum(n
um))
else:
if( op t=2 ):
-
print("Sum of' ,nu m, "is : ",sum(num
))
else:
print(" ")

OUTPUT:
Enter any number : 5
.
1-To find the factorial, 2-To fiin d the sum 3-Exit

Enter the option 1-3 : 1


Factorial of 5 is: 120

Enter any number: 5


. 2-To find the sum 3- Ex1·t
1-To find the factonal,
·
. n 1-3·2
Enter the optto ·
Sum of 5 is:15

) LC:_)
A3. Write a python progratn usin d fi d .
and com ared . g user e ne function to calculate interest amount using simple interest method
P mterest method and find the difference of interest amount between the two methods.
for

#Simple and Compound Interest

# Reading principal amount, rate and time


def simplnt(p,t,r):

si = float(p*t*r/100)
return si

def complnt(principal,time,rate):

ci = float(p* ((l+r/100)** t - I))


return ci

p = float(input('Enter amount:'))
f
t = float(input('Enter time:')) I
r = float(input('Enter rate:')) I

si=simplnt(p,t,r)

ci=complnt(p,t,r)

print('Simple interest is Rs. %8.2f' % si)

print('Compound interest is Rs. %8.2f' % ci)

diffint=ci-si;

print("Difference is Rs. %8.2f" % diffint)

OUTPUT:

Enter amount: 45000

Enter time: 3

Enter rate: 12.5

Simple interest is Rs. 16875.00

Compound interest is Rs. 19072.27 AS]


Difference is Rs. 2197.27

A4. Write a Python Program to read a text file and display the number of vowels, consonants,
uppercase and lowercase characters in the file

# Python Program to create a text file and to read a text file and display the number of
# vowels, consonants, uppercase and lowercase characters in the file

def count_characters(file_name):
vowels = "aeiouAEIOU"
v count =0
c count =0
upper_count = 0
lower_count = 0

PU BOARD LAB MANUAL 136


with open(file_name, "r") as file:
text = [Link]()
for char in text:

if [Link] ( ):

if char in vowels:
v count + =l
else:
c count + =I

if [Link]:
upper _count + = I

elif [Link]():
lower count + = I

print("Vowels:" , v_count)
print("Consonants: ", c_count)
print("Uppercase characters: ",upper_count)
print("Lowercase charac ters:", lower_count)

def create_text_file( file_name, content):


with open(file_name, "w") as file:
file. write(content)

file name = "[Link]"


content = input("enter few sentences to create a text file with content: ")
create_text_file(file_ name, content)

count_characters(file_name)

OUTPUT:
enter few sentences to create a text file with content: This progr
am is TO Create ·a FILE
Vowels: 11
Consonants: 15
Uppercase characters: 8
Lowercase characters: 18

AS) Write a python code to count the number of lines, number


of words and number of characters
in a text file.

# Python program to count numb er of lines,


# Words and character in textfile
def count_text(file_name):

linecount =O
wordcount =O
charcount =O
with open(file_name, "r") as file:

PU BOARD LAB MAN UAL


137
for line in file:

linecount + =I
wordcount + = len([Link]())

charcount + = len(line)
print("Lines: ", Iinecount)
print("Words: ", wordcount)
print("Characters: ", charcount)

def create- text- file(file- name, content):

with open(file_name, "w") as file:

file. write(content)

file_name = "[Link]"
content = """Hello Students
This is a sample text file.

It contains multiple lines."""

create_text_file(file_name, content)

count_text(file_name)

OUTPUT:
Lines: 3
Words: 12
Characters: 70

A6) Write a python program to create and to read records in binary file with student name and
marks of six subjects.

import pickle
while True:
print("' I. Create Binary File.
2. Display the File.
3. Exit"')
a = int(input('choose a command (1-2,3-exit): '))
if a== I:
f open('[Link]','wb')
X int(input('How many student: '))

for i in range(x):
name = input('Name: ')
english = int(input('English Mark: '))
Ian = int(input("Language Marks"))
phy = int(input('Physics Mark: '))
chem = int(input('Chemistry Mark: '))
maths = int(input('Maths Mark: '))

PU BOARD LAB MAN


cs
t =
- int(input('CS Mark:'))
(name, english, Ian, phy, chem, maths, cs]
[Link](t.0

[Link]{)
elif a== 2: open('studenldat','rb')
f =
try:
while True:
p = [Link](t)
print(p)
except
[Link]()
ifa> 2:
brea k

OUTPUT:
1. Crea te Binary File.
2. Display the File .
3.E m
choose a com man d (1-2, 3-exit): 2
('Bharath', 77, 88, 99, 77, 88, 99)
('Gu ru', 77, 88, 99, 77, 88, 99)
('Ma njul a', 88, 99, 88, 99, 88, 88)
['Re kha' , -99, 88, 99, 99, 88, 88)
['Od ay', 66, 77, 66, 77, 66, 77)
1. Crea te Bina ry File.
2. Disp lay the File. . . ..~·
3. Exit
choose a com man d (1-2,9-exit):3
above
of the students having percentage 90 and
Write a python program to copy the records
from the binary me into another file.
into another file.
# program to create and copy records to
copy records with percentage 90 and above
import pickle
while True:
print('" I. Create Biruuy File.
2. Display the main File.
3. Create new file wirh >90
4. Exit'")
·
a = int(input('choose a command (1-2,9-exit): '))
ifa= =l:
f = open('studentdat','wb')
0 = open('[Link]','wb')
X = int(input('How many student:'))
for i in range(x):
name = input('Name: ')
english = int(input('English Mark:'))
Ian = int(input("Language Marks"))
phy = int(input('Physics Mark:'))
chem = int{input('Chemistry Mark:'))
maths= int(input('Maths Mark: '))
cs = int(input('CS Mark:'))
total = phy+chem+cs+maths+english+lan
139
PU BOARD lAB MANUAL
-
,• •P"lF"""CS.,......_ _ _ __ _ _ _
_,_,_ ,.,.. ITIIIP'Y ..~ .~ - - -- -- - - -- - - - - - --

per = (total/600) • 100


t = [name, english, Ian, phy, chem, maths, cs, total, per]

I g =
[Link](t,f)
if per>= 90:
[name, english , Ian, phy, chem, maths, cs, total, per]

[Link](g,o)
[Link]()
[Link]()
elif a== 2:
f = open('[Link]','rb')
try:

I except:
while True:
p =-[Link](f)
print(p)

[Link]()
elif a== 3:
print("Studets with> 90 Marks")
f = open('[Link]','rb')
try:
while True:
o = [Link](f)
print(o)
except:
[Link]()

else:
break

OUTPUT:
1. Create Binary File.
--- - rilliplay the main File.
·3. Create new file wirh >90
. 4. Exit
choose a command (1-2,9-exit): 2
['Bharath', 77, 88, 99, 88, 77, 77,506, 84.33333333333334]
['Guru', 88, 77, 88, 77, 88, 77,495, 82.5)
['Manjula', 88, 77, 88, 88, 77, 77,495, 82.5)
['Rekha', 99, 88, 99, 88, 99, 88, 561, 93.5)
['Uday', 99, 99, 99, 99, 99, 99, 594, 99.0]
1. Create Binary File.
2. Display the main File.
3. Create new file wirh >90
4. Exit
choose a command (1-2,9-exit): 3
Studets with > 90 Marks
('Rekba', 99, 88, 99, 88, 99, 88, 561, 93.5]
('Uday', 99, 99, 99, 99, 99, 99,594, 99.0)
1. Create Binary File.

PU BOARD LAB MANUAL 140


2. Display tbe main FUe.
l. Create new file wirh >90
4. Exit
cboose • ~m~and (1-2,9-exlt):4

AB. Write a python program using function to sort the elements of a list using bubble sort
method

# program using function to sort the elements of list using bubble sort method
def bubble(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1 ):
if arr[j] > arr[j+ I]:
arr[j], arr[j+ I] = arr[j+ 1], arr[j]

def bubble_inO:
arr=O
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
element= int(input("Enter element"))
[Link](element)
return arr
arr = bubble_inO
print("Original list:", arr)

bubble(arr)
print("Sorted list:", arr)

OUTPVf;
Enter the number of elements in the list: 5
Enter element 34
Enter element 56
Enter element 23
Enter element 12
Enter element 34
Original list: [34, 56, 23, 12, 34]
Sorted list: [12, 23, 34, 34, 56]
A9. Write a python program using function to sort the elements of a list using selection sort

Method

# Selection sort in Python


# Selection sort in Python
def selection(arr):
n = len(arr)
for i in range(n):
minindex = i
for j in range(i+ 1, n):
if arr[j] < arr[minindex]:
minindex= j
arr[i], arr[minindex] = arr[minindex], arr[i]

def selectioninQ:
arr= D
n = int(input("Enter the number of elements in the list: "))
for i in range(n):
ele = int(input("Enter element"))
[Link]( ele)
return arr
arr = selectionin0

print("Original list:", arr)

selection(arr)
print("Sorted list:", arr)

OUTPUT:
Enter the number of elements in the list: S
Enter element 32
Enter element 45
Enter element 67
Enter element 34
Enter element 23
Original list: [32, 45, 67, 34, 23)
Sorted list using insertion sort method: [23, 32, 34, 45, 67)
l
,d 0. Write a python program using functi on to sort the eleme
nts of a list using Insertion sort
method

# python program using function to sort the elements of list using inserti
on sort method
definsertion(arr):
for i in range (l, len(arr)):
key= arr[i]
j =i - 1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j-= 1
arr[j + 1] = key

def insertioninO:
am= D
n = int(inp ut("En ter the number of elements in the list: "))
for i in range (n):
eleme nt= int(input("Enter element"))
[Link] pend(element)
return arr

arr = insertioninO
print("Original list:", arr)

insertion(arr)
print("Sorted list using insertion sort meth0d:", arr)

OUTPUT:

Enter the number of elemen ts in the list: 5


Enter element 55
Enter element 43
Enter element 23
Enter element 43
Enter element 65
651
Original list: [55, 43, 23, 43' rt method: [23, 43, 43, 55, 65)
. erdOD so
Sorted list using ins
list using linear search
. .to search an element i n
All. Write a python program using function
8

method

# Search function with parameter list name


# and the value to be searched - Linear Search

deflinear(arr, target):
for inde~ ele in enumerate(arr):
if ele = target:
return index return
-I
deflinearinO:
arr= D
n = int(input("Enter the number of elements ="))
for i in range(n):
ele = int(input("Enter element"))
[Link](ele)
return arr

arr= linearinO
target= int(input("Enter the element to search for: "))

result= linear(arr, target)


if result != -I:
print(target, "Element found at index", result).. ,
else:
print(target, " Element not found in the list.")

OUTPUT:

Enter the number of elements in the list: 5 Enter


element 23
Enter element 4
Enter element 5
Enter element 6
Enter element 45
Enter the element to search for: 55
55 Element not found in the list.
I
' --

All. Write • python program using function to search an element in a list using binary search

method.

defbinaI)'(arr, target):
beg, end= 0, len(arr)- 1 : ;

while beg<= end:


mid= (beg+ end) //2 if . ' ,

arr[mid] = target:
return mid
elifarr[mid] < target:
beg=mid+ 1
else:
end=mid-1
return-I

defbinaiyinQ: arr
=□
n = int(input("Enter the number of elements="))
for i in range(n):
ele= int(input("Enterthe elements in as~ending order.")) '·:,:·· i •- -,,: ::'. j 1 ;

[Link](ele)
return arr
· ·
'
'
~ ~ .
.,... .· . ·tr "7' ••••
.
~ •. ' '... .,

I .

arr= binaryinO Et -~1 ...-»!., t:'rl . l~:~i1.\ .,.~


target = int(input("Enter the element to search for: "))

result= binary_search(arr, target)


if result != -1: :- ~-
print(target, "Element found at index", result)
else:
print(target, "Element not found in the list.")

OUTPUT: ·

Enter the number of elements in the list: 5


Enter the elements in ascending order 12
Enter the elements in ascending order 23
. -·: . ,·
Enter the elements in ascending order 34
Enter the elements in ascending order 454
Enter the elements in ascending order 656
Enter the element to search for: 34

34 Element found at index 2


~ , W Mt &JE W

fffsplay elements from a stack using list


A13. Write a python program to add and

# initial empty stack stack =


[]
#PUSHing the elements into a stack
print("initially stack is empty :",stack)

[Link]('x')
[Link]('y')
[Link]('z')

ck)
print("After PUSHING stack is:") print(sta

#POPing the elements from a stack


print('After POPped from stack: ')
print(stack. pop()) print(stackpopO)
print(stack. pop())

ed:') prin~stack)
print('\n my_stack after elements are pop

OUTPUT:

initially stack is empty : [J


Mter PUSHING stack is
['x', 'y', 'z'J
Mter POPped from stack: z
yx

my_stack after elements are poped: (J


A14. Write a python program to add and display 'etem~nts from a queue using list

# python program to add and display elements from a queue using list#
ereate Queue and perform insert and delete ·

unPort queue

# Display the elements in the queue def


display_queue(q):
print("Queue elements are:", end="")

while not [Link]:

ele == [Link] .(i. • •

print(element, end=" ")


print(1\n Queue size after REMOVE is', [Link])

• '1 •• : j \ • • ;, • • •

l , • . ,--:· - ~,,.t!•··~-;~ '~-:"~~

•' :1• • ~•: I:;: ~; •,;. •.- ~~ T f ',


# Create a Queue object f : • •, i,'.

q == [Link] . • • ..., f

#Add elements to the queue using put()


I.
[Link](IO)
[Link](20) · \

' ' ·.:: \·- "..: .-,,.0. .-~ '


[Link](30)
print('Queue size after INSERT is', [Link]) ..
\ .
. •.
•!
'. ~ : '' ~

#Display the elements in the queue . ...,


I
•·
• :•

display_queue(q) . ' ·-' - ··--· ... ~--- .. ·.. ..·


' ' ! ,. . '.. '- ' ~: '
,• '•t t \ • ·.'
OUTPUT:

Queue size after INSERT is 3 Queue x


.. · .. ' ' ' I .j ...' t .•
elements are: 10 20 30 Queue size I,

,..
. • 'l .

after REMOVE is O • I

' ;

I •

~ • • •, I f : f• ; / ' • . 1, ' • ' o I

' ' '

f .t :

80ARD LAB MANUAL


PARTB

MYSQL
Bl) Create a table with the following fields and enter IO records into the table.
Entity Name: marks jS
(iiJ 0
Attribute name Type Size Constraints
Rollno Int 5
Sname Varchar 15 Not null
Lang mks Int 3 Between 0 and 100
Eng mks Int 3 Between 0 and 100
Subl mks Int 3 Between 0 and I 00
Sub2 mks Int 3 Between 0 and I 00
Sub3 mks Int 3 Between 0 and I 00
Sub4 mks Int 3 Between 0 and I 00

CREATE TABLE marks (


Rollno INT(S),
Sname V ARCHAR( l5) NOT NULL,
Lang_mks INT(3) CHECK (Lang_mks BETWEEN 0 AND 100), (vi) Li
Eng_mks INT(3) CHECK (Eng_mks BETWEEN 0 AND 100),
Subl_mks INT(3) CHECK (Subl_mks BETWEEN 0 AND 100),
Sub2_mks INT(3) CHECK (Sub2_mks BETWEEN 0 AND 100), (vii) J,
Sub3_mks INT(3) CHECK (Sub3_mks BETWEEN 0 AND 100),
Sub4_mks INT(3) CHECK (Sub4_mks BETWEEN 0 AND 100)
);
Bl) C

l
Data to be entered: (Values are indicative)

Rollno Sname Lane mks Ene: mks Subl mks Sub2 mks Sub3 mks Sub4 mks
1010 RAJ 89 97 98 99 86 95
1026 KIRAN 67 62 72 86 72 62
1042 ANAND 78 87 92 82 72 76
1250 RAM 72 86 72 62 87 68
5212 VIJAYA 46 58 86 92 72 62
3622 MANOJ 86 56 62 86 52 64
1948 REEHAN 63 68 52 56 96 76 CRE
1482 KAJOL 49 54 48 76 62 55 R1
1947 KUMAR 98 98 99 100 97 99 Cl
1951 REEMA 82 72 62 98 73 64 BJ
INSERT INTO marks VALUES(toto, 'RAJ', 89, 97, 98, 99, 86, 95) lJJ
);
INSERT INTO marks VALUES (1026, 'KIRAN', 67, 62, 72, 86, 72, 62)
INSERT INTO marks VALUES (1042, 'ANAND', 78, 87, 92, 82, 72, 76)
INSERT INTO marks VALUES (1250, 'RAM', 72, 86, 72, 62, 87, 68)
INSERT INTO marks VALUES (5212, 'VIJAYA', 46, 58, 86, 92, 72, 62)
INSERT INTO marks VALUES (3622, 'MAN OJ', 86, 56, 62, 86, 52, 64)
INSERT INTO marks VALUES (1948, 'REEHAN', 63, 68, 52, 56, 96, 76)
INSERT INTO marks VALUES (1482, 'KAJOL', 49, 54, 48, 76, 62, 55)
INSERT INTO marks VALUES (1947, 'KUMAR', 98, 98, 99, 100, 97, 99)

BOARD LAB MANUAL


148
(i) List all the records
select • from marks;

(ii) Display the descript ion of the table


describe marks;

(iii) Add the new attribute s total and percent


alter table marks add(total int(3), percent float(5,3));

(iv) Calcula te total and percent age of marks for all the students
update marks set total= lang_m ks+eng _mks+s ubl_mks+sub2_mks+sub3_mks+sub4
_mks;
update marks set percen t= total/600*100;

(v) List the students whose percenta ge _o f marks is more than 60%.
select sname, percent from marks where percent >=60;

(vi) List the students whose percenta ge is between 60% and 85% . .
select sname, percent from marks where .percent between 60 and 85;

(vii) Arrange the students based on percentage of marks from highest to lowest.
select sname, percent from marks order by percent desc;

B2) Create a table for house hold Electricity bill with the· following fields and enter
10 records.
Entity Name: BESCOM

Attributename Type Size Constraint


RRNO Varchar 10 Primary .key
CUSTN AME Varchar 25 Not null
BILLDA TE DATE
UNITS INT 4

CREATE TABLE BESCOM (
RRNO VARCHA R(l0) PRIMARY KEY,
CUSTNAME VARCHAR(25) NOT NULL,
BILLDATE DATE,
UNITS INT(4)
);

BOARD LAB MANUAL


Data to be entered: (Values are indicative)

RRNO CUSTNAME BILLDATE UNITS


El 120 RAJ 2024-05-5 250
E2210 KIRAN 2024-03-26 178
El450 ANAND 2024-04-15 56
E2126 RAM 2024-05-8 782
E1562 MANJULA 2024-05-2 562
E6221 MANOJ 2024-05-18 72
E5822 REEHAN 2024-02-19 92
El692 KAJOL 2024-03-25 73
E6721 KUMAR 2024-07-14 589
E2682 REEMA 2024-05-11 100

INSERT INTO BESCOM VALUES('E1120', 'RAJ', '2024-05-05', 250)


INSERT INTO BESCOM VALUES ('E2210', 'KIRAN', '2024-03-26', 178)
INSERT INTO BESCOM VALUES ('E1450', 'ANAND', '2024-04-15', 56)
INSERT INTO BESCOM VALVES ('E2126', 'RAM', '2024-05-08', 782) _
INSERT INTO BESCOM VALUES ('E1562', 'MANJULA', '2024-05-02', 562) -
INSERT INTO BESCOM VALUES ('E6221', 'MANOJ', '2024-05-18', 72)
INSERT INTO BESCOM VALUES ('E5822', 'REEHAN', '2024-02-19', 92)
INSERT INTO BESCOM VALUES ('E1692', 'KAJOL', '2024-03-25', 73)
INSERT INTO BESCOM VALUES ('E6721', 'KUMAR', '2024-07-14', 589)
INSERT INTO BESCOM VALUES ('E2682', 'REEMA', '2024-05-11', 100); _.
• • - J

7. View the structure of table.


describe bescom; , _

8. List all the records


Select * from bescom;

9. Add a new field for bill amount in the name of billamt.'


ALTER TABLE [Link] BILLAMT FLOAT(7,2); ·

I0. Compute the bill amount for each consumer as per the following rules: _
· a. MINIMUM Amount Rs. 100 ·
b. For first 100 units Rs 7.50/Unit
c. For the above 100 units Rs. 8.50/Unit .··: , . ·, .: ·
(i) UPDATE BESCOM SET BILLAMT = 100 + UNITS * 7.50 WHERE UNITS<= 100;
• • t ... - -.... : ~ / .- '

(ii) UPDATE BESCOM SET BILLAMT = 100 + (100 * 7.50) + (UNITS - 100) * 8.50 WHERE
UNITS> 100;

I I .Display the maximum, minimum and total bill amount.


SELECT MAX(BILLAMT), min(billamt), avg(billamt), sum(bill11mt) FROM BESCOM;

[Link] all the bills generated in a sorted order based on RRNO.


select rrno from bescom order by rrno;
B3) Create a table with the following details and enter 10 records into the table.

BOARD LAB MANUAL


Entity Name: student
Attribute name Type Size Constraint
Rollno int 5 Primary key
Sname Varchar 15 Not null
DOB date
Gender char l
Combn Varchar 5
Class Char 6

CREATE TABLE student (


· Rollno int(5) PRIMARY KEY,
Sname VARCHAR(15) NOT NULL,
doh date, r· •·•::..i,_; • , ..
Gender CHAR(l ),
Combn VARCI:IAR{5)," ' : : '"" i r-: 0 :~ ; :>r(f
-

Class varCHAR(6)· e. :; ,..,"' •:' '> A,:,r··· ·/ .,..


-: .. .. J
,,,.
..
I

'

ta to be entered: ( Values are indicative)


Gender Combo Class
RollNo Sname DOB

12', ·,_M',°iPCMC','2B'); · ·: .··.·_; , :.i: · ' : ::: ·_· -.,.


insert into stud~nt valu_e~ (3739, 'U,day',;20.~4-9-
stud ent vahies (1001, 'Raj Kum ar', '200 5-5- 21', 'M', 'BASC','2A'); -_ :·;- ·. ,--,. , . . . ··;·,
insert into ·: -.-- -~- ___.... ~'. :-·:- ' 1

n•~11004--11-lSi, 'M', 'PCMC','2Bij;° '


insert m:io stud ent,~alues (100 5, i<.'i ra'1

, !M', 'CEBA','2C'); .· ·__·_ ···. ·.,._ . : . ·..i ·.'


into stud e~t values (104 2; 'An and ', '200 5-12 -22' ,
insert ' , ,
:· _ ,- . _ · · · :
.
-18', 'M', 'PCMC','2A'); ) ..
, --
insert into student values (1250, 'R~m', '2004~6
28'·, 'F', 'PCMC','2A'); ·· · ,.. ·. ·, ·.·. , . ·;.:·_ · . · ,_
1

insert into student vaiues (5212,· 'Vijay~•: '2007-7- ; ·: __ ~-. _·. _· _.;· ,. .
rt into .studen t valu es (1~29, 'Bha ra~h ', '200 5-1-12', 'M', 'BASC','2B'); .
inse
8', 'F', 'CEBA','2C'); _·_ ,_· ·
insert inio student values (2152; 'Rekha', '2006-6-
5-4-17', 'M', 'CEBA','2C');
insert into student values (1948, 'Reehan', '200
·· ' .. l t • • •

5-8.:.is·~ 'F', 'PCMC','2B');


· .
_,. I

insert into [Link] values (2443, 'Manjula', '200

(i) List all the students .


I .,
\ ·
. \' ' \

. . select * from student; , . .


(ii) List only th6se'students who are in BASC and CEBAcoinbination. · · ·: .,:
combn='CEBA';
select * from student where combn='BASC' or ..
e values.
(iii) List only the combination by removing duplicat
select distinct(combn) from student; ·
(iv) List the students alphabetically.
.'
select sname from student order [Link]; · · ··
. . .,
(v) List the students alphabeticallyclass-wise.
select sname, class·from student group by clas
s order by sname;
··. \

·of any year.


(vi) [Link] stude~~ who born [Link] month of.J~e
-SELECT* FROM student WHERE MONTH(dob)
= 6;
(vii) Count the number of students Gender-wise.
SELECT gender, COUNT(*) FROM student GROUP BY gender;
B4) Create a table with following fields and enter IO records into the table.
Entity Name: Library

Attributename Type Size Constraint


Title I Varchar 75 Not null
Author Varchar 60
Year int 4
Category Varchar 25
price float 7,2
Qty Int 4

CREATE TABLE Library ( :C [Link]


Title VARCHAR(75) NOT NULL, Author
VARCHAR(60),
[Link] \ ool'I ,n '30"'-" eje~
Year INT(4), 'J:k m~~e & ""e 50 'o\i"d
Category VARCHAR(25), Price
FLOAT(7,2),
Qty INT(4)
);

Data to be entered: __{yalues are indicative)


Tide Author Year Category Price Qty
The Data Science Handbook Darshan 2019 Data science 750 12
Introduction to Computer Programs Harshavardhan null Computer Science 700 6 ..
Computer Science Text book Class 12 ReetaSahoo 2019 Textbook , 450 4
A book on AI . ' . Sagar I 2016 AI 200 7 ·,
Robots and Automation ~
Dushyanth . 2018 Digital Technology 750 9
AI2041 Chen&Lee. 2021 AI 1000 2
Computer Hardware and Software Chethan 2000 Computer science 500 7
The Future ofWorlc '. Dev Kumar 2018 Digital Technology 750 ·· 4
Healthcare and AI Eshwar . 2019 AI 950 9
Introduction to Data Science Dravid 2014 Data Science 400 5 -·

INSERT INTO Library VALUES('The Data Science Handbo~k', '~arshan', 2019, 'Da~ scienc~',
750.00, 12) . .. . .
~SERT INTO Library VALVES ('Introduction to Computer Programs', 'Harshavar~an', NULL,
'CoJPPuterScience', 700.00, 6) . . · ·. ..
INSERT INTO Library VALUE~ ('Computer Science Text book Class 12', 'Reeta Sahoo', 2019,
Textbook', 450.00, 4) . · , . . , . _ ·
INSERTJNTO Library VALVES ('A book on AI', 'Sagar', 2016, 'AI', 200.00, 7)
INSERT INTO Library VALVES ('Robots and Automation', .'Dushyanth', 2018, 'Digital ·
Technology', 750.00, 9) · . · : . :.
INSERT INTO Library VALUES ('AI 2041', 'Chen & Lee', 2021, 'AI', 1000.00, 2) . . ..
INSERT INTO Library VALVES ('Computer Hardware and Software', 'Chethan', 2000, 'Computer
science', 500.00, 7) : ··· ·· i •; .

INSERT INTO Library VALVES ('The Future ofWork~, 'Dev Kumar', 2018, 'Digital Technology',
750.00, 4) · · . ·· · · , . . . .. .
BOARD IAB MANUAL . . . : . . 152
INSERT INTO Library VALUES ('Healthcare d AI' ·,
INSERT INTO Library VALUES ('lntroductio a~ D , ESs~war\ 2019, 'Al', 950.00 9)
400.00 ' S)·' - n ° . ,
ata cience, 'Dravid' ' 2014, •u'ata Science'

(i) List all the books


select* from library;
(ii) Calculate Amount by altering table by addi· ng a new co1umn· 'Amount'
(a) alter table library add(amount float(' l))· ·•
(b) update library set amount = price * q~; '

(iii) List the records of all those books pric~ is between 400 and 900
select price from library where price between 400 and 900;

(iv) List those records with no value in the attribute year.-


select title, year from library where year is NULL;

(v) List the names of the authors whose name starts with letter 'C' or 'D'.
select Author from library where author like 'C%' or author like 'D%';

(vi) List Title, year and category from the table library with category field has word 'science'.
SELECT Title, Year, Category FROM Library WHERE Category LIKE '%science%';

(vii) List all those records whose year of publication is 20 IO onwards with book price is iess than
Rs.750.
SELECT year, price FROM Library WHERE Year>= 2010 AND Price< 750;

You might also like