0% found this document useful (0 votes)
14 views

CS-Practical Programs-2023-24

CS-Practical programs-2023-24 (1)

Uploaded by

Switch Blade
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)
14 views

CS-Practical Programs-2023-24

CS-Practical programs-2023-24 (1)

Uploaded by

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

VELAMMAL VIDHYASHRAM SURAPET

COMPUTER SCIENCE

2023-2024

CLASS - XII

VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024


EX.NO.1
DATE:
Creating a Menu driven program to perform Arithmetic
operations.
AIM:
To write a menu driven python program to perform Arithmetic
operations based on the user’s choice.
SOURCE CODE:
#function for addition of two numbers
def addition(a, b):
sum = a + b
print(a, "+", b, "=", sum)

#function for subtraction of two numbers


def subtraction(a, b):
difference = a - b
print(a, "-", b, "=", difference)
#function for multiplication of two numbers
def multiplication(a, b):
product = a * b
print(a, "*", b, "=", product)

#function for division of two numbers


def divide(a, b):
quotient = a / b
remainder = a % b
print("Quotient of", a, "/", b, "=", quotient)
print("Remainder of", a, "%", b, "=", remainder)

#Heading of menu-driven approach


VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
print("WELCOME TO CALCULATOR")

#using the while loop to print menu list


while True:
print("\nChoose the operation to perform:")
print("1. Addition of two numbers")
print("2. Subtraction of two numbers")
print("3. Multiplication of two numbers")
print("4. Division of two numbers")
print("5. Exit")

choice = int(input("\nEnter your Choice: "))

#Calling the relevant method based on users choice using if-else loop
if choice == 1:
print("\nAddition of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
addition(a,b)

elif choice == 2:
print("\nSubtraction of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
subtraction(a,b)

elif choice == 3:
print("\nMultiplication of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
multiplication(a,b)
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
elif choice == 4:
print("\nDivision of two numbers")
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
divide(a,b)

#exit condition to get out of the while loop


elif choice == 5:
print("Thank You! Bye.")
break
else:
print("Invalid Input! Please, try again.")

VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024


SAMPLE OUTPUT
WELCOME TO CALCULATOR

Choose the operation to perform:


1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit

Enter your Choice: 1

Addition of two numbers


Enter the first number: 5
Enter the second number: 5
5 + 5 = 10

Choose the operation to perform:


1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit

Enter your Choice: 2

Subtraction of two numbers


Enter the first number: 5
Enter the second number: 5
5-5=0
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
Choose the operation to perform:
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit

Enter your Choice: 3

Multiplication of two numbers


Enter the first number: 5
Enter the second number: 5
5 * 5 = 25

Choose the operation to perform:


1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit

Enter your Choice: 4

Division of two numbers


Enter the first number: 25
Enter the second number: 5
Quotient of 25 / 5 = 5.0
Remainder of 25 % 5 = 0

Choose the operation to perform:


VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
1. Addition of two numbers
2. Subtraction of two numbers
3. Multiplication of two numbers
4. Division of two numbers
5. Exit

Enter your Choice: 5


Thank You! Bye.

Result:

The above output has been verified in the terminal.

VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024


EX.NO.2

DATE:
LIST SWAP
A List contains the following elements N1=[3,25,13,6,35,8,14,45]
Write a user defined function swap ( ) that takes in lst as a parameter
and swaps the content with the next value divisible by 5 so that the
resultant list will look like:
[25, 3, 13, 35, 6, 8, 45, 14]
AIM:
To write a user defined function swap ( ) that takes in lst as a
parameter and swaps the content with the next value divisible by 5
SOURCE CODE:
def swap(lst):
for i in range(len(lst)-1):
if lst[i+1]%5==0:
lst[i],lst[i+1]=lst[i+1],lst[i]
for i in range(len(lst)):
print(lst[i],end=' ')
lst=[]
while True:
print("\nChoose the operation to perform:")
print("1.list creation")
print("2.swap value")
print("3.Exit")
ch=int(input("Enter your choice"))
if ch==1:
lst=eval(input("Enter a list"))
elif ch==2:
swap(lst)
elif ch==3:
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
break
else:
print("Invalid Choice")

SAMPLE OUTPUT:

choose the operation to perform:


1. list creation
2. swap value
3. Exit
Enter your choice1
Enter a list[3,25,13,6,35,8,14,45]

Choose the operation to perform:


1.list creation
2.swap value
3.Exit
Enter your choice2
25 3 13 35 6 8 45 14
Choose the operation to perform:
1.list creation
2.swap value
3.Exit
Enter your choice3

Result:

The above output has been verified in the terminal.

VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024


EX.NO.3

DATE:
String Operations
AIM:
To write a menu driven program in python using user defined
functions to take string as input and
(i) To check whether the given string is palindrome or not.
(ii) To count number of occurrences of a given character.

SOURCE CODE:
def palindrome(s):
rev=s[::-1]
if rev==s:
print("The String is palindrome")
else:
print("The string is not a palindrome")

def Count(st,choice):
c=st.count(ch)
return c
#Main program
while True:
print("Menu")
print("1.palidrome")
print("2.To count number of occurrences of a given character")
print("3. Exit")
opt=int(input("Enter your choice:"))
if opt==1:
s=input("enter the string:")
palindrome(s)
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
elif opt==2:
st=input("Enter the string:")
ch=input("Enter a character")
cnt=Count(st,ch)
print("The character",ch,"is present in",st,"is",cnt,"times")
elif opt==3:
break
else:
print("Invalid Choice")

SAMPLE OUTPUT:
Menu
1. palidrome
2. To count number of occurrences of a given character
3. Exit
Enter your choice:1
enter the string:race
The string is not a palindrome
Menu
1. palidrome
2. To count number of occurrences of a given character
3. Exit
Enter your choice:2
Enter the string:race
Enter a charactera
The character a is present in race is 1 times
Menu
1. palidrome
2. To count number of occurrences of a given character
3. Exit
Enter your choice: 3
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
Result:
The above output has been verified in the terminal.

VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024


EX.NO.4

DATE:
List Search
AIM:
To write a python program that uses a function search () which
takes a list and element as a parameter and searches an element in a
list and displays the position of the element present in the list and its
frequency

SOURCE CODE:

def search(lst,ele):
found=False
for i in range (len(lst)):
if ele==lst[i]:
found=True
print("Position",i,end=' ')
if found:
print("Frequency",lst.count(ele))
else:
print("Element not found")
lst=[]
while True:
print("1.List creation")
print("2.Search value")
print("3.Exit")
ch=int(input("Enter your choice"))
if ch==1:
lst=eval(input("Enter list elements"))
elif ch==2:
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
x=int(input("Enter the element you want to search"))
search(lst,x)
elif ch==3:
break
else:
print("Invalid choice")

Sample Output:
1. List creation
2. Search value
3. Exit
Enter your choice1
Enter list elements [1, 2, 3, 4, 1, 2]
1. List creation
2. Search value
3. Exit
Enter your choice2
Enter the element you want to search2
Position 1 Position 5 Frequency 2
1. List creation
2. Search value
3. Exit
Enter your choice3
>>>

Result:

The above output has been verified in the terminal.

VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024


EX.NO.5

DATE:
Dictionary –Create and Update
AIM:
To write a python script to print a dictionary where the keys are
numbers between 1 and 15(both included) and the values are square of
keys. Also write a function search () that takes in the dictionary d as
parameter and searches for a particular key, if found returns the
corresponding value, if not found, an error message will displayed.
Sample dictionary
{1:1,2:4,3:9,4:16,…15:225}

SOURCE CODE:
def search(d):
x=int(input("Enter a key-value to search"))
if x in d.keys():
print("key",x,"is found, the value is",d.get(x))
else:
print('key not found')
d={}
for i in range(1,16):
d[i]=i*i
print(d)
while True:
print("1.Search for a value")
print("2.Exit")
ch=int(input("Enter your choice:"))
if ch==1:
search(d)
elif ch==2:
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
break
else:
print("invalid choice")

Sample Output:
Run1
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121,
12: 144, 13: 169, 14: 196, 15: 225}
1. Search for a value
2. Exit
Enter your choice: 1
Enter a key-value to search5
key 5 is found, the value is 25
1. Search for a value
2. Exit
Enter your choice: 2
>>>
Run2:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121,
12: 144, 13: 169, 14: 196, 15: 225}
1.Search for a value
2.Exit
Enter your choice:1
Enter a key-value to search16
key not found
1.Search for a value
2.Exit
Enter your choice:2
>>>
Result:
The above output has been verified in the terminal.
VVS/COMPUTER SCIENCE PRACATICAL/ 2023-2024
EX.NO:6

DATE:

CREATING A PYTHON PROGRAM TO READ A TEXT FILE LINE BY LINE AND


DISPLAY EACH WORD SEPARATED BY '#'

AIM:
To write a Python Program to Read a text file "Story.txt" line by line and display
each word separated by '#'.

SOURCE CODE:

Result:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Story.txt:

***************************************************************************************
EX.NO:7

DATE:

CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY THE


NUMBER OF VOWELS/CONSONANTS/LOWER CASE/ UPPER CASE CHARACTERS.
AIM:
To write a Python Program to read a text file "Story.txt" and displays the number of
Vowels/ Consonants/ Lowercase / Uppercase/characters in the file.

SOURCE CODE:

Result:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Story.txt:

***************************************************************************************
EX.NO:8

DATE:

CREATING A PYTHON PROGRAM TO COPY PARTICULAR LINES OF A TEXT FILE


INTO AN ANOTHER TEXT FILE

AIM:

To write a python program to read lines from a text file "Sample.txt" and copy those lines
into another file which are starting with an alphabet 'a' or 'A'.

SOURCE CODE:

Result:
Thus the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:
Python Executed Program output:

Sample.txt:

Python Executed Program Output:

New.txt:

*****************************************************************************************
EX.NO:09

DATE:

CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN


BINARY FILE

AIM:
To write a Python Program to Create a binary file with roll number and name. Search
for a given roll number and display the name, if not found display appropriate
message.

SOURCE CODE:

Result:
Thus , the above Python program is executed successfully and the output is verified.
SAMPLE OUPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

************************************************************************************
EX.NO:10

DATE:

CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY RECORDS IN


BINARY FILE
AIM:
To write a Python Program to Create a binary file with roll number, name, mark
and update/modify the mark for a given roll number.

SOURCE CODE:

Result:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:
PYTHON PROGRAM EXECUTED OUTPUT:

**********************************************************************************
EX.NO: 11

DATE:

CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE’S RECORD


IN CSV FILE.

AIM:

To write a Python program Create a CSV file to store Empno, Name, Salary and search
any Empno and display Name, Salary and if not found display appropriate message.
SOURCE CODE:

Result:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:
PYTHON PROGRAM EXECUTED OUTPUT:

******************************************************************************
EX.NO: 12

DATE:
CREATING A PYTHON PROGRAM TO PERFORM READ AND WRITE
OPERATION WITH CSV FILE

AIM:

To write a Python program Create a CSV file to store Rollno, Name, marks and read
the content from csv file.

SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is verified.

SAMPLE OUTPUT:
PYTHON PROGRAM EXECUTED OUTPUT:
********************************************************************************************
Ex.no.13

Write a python program to maintain book details like book code, book title and price using
stacks data structures? (Implement push (), pop () ,peek () and traverse () functions)

AIM: To write a python program to maintain book details like book code, book title and price using stacks
data structures
book=[]
def push():
bcode=input("Enter bcode ")
btitle=input("Enter btitle ")
price=input("Enter price ")
bk=(bcode,btitle,price)
book.append(bk)

def pop():
if(book==[]):
print("Underflow / Book Stack in empty")
else:
bcode,btitle,price=book.pop()
print("poped element is ")
print("bcode ",bcode," btitle ",btitle," price ",price)

def peek():
if book==[]:
print("Book stack is empty")
else:
top=len(book)-1
print("the top of the book stack is :",book[top])

def traverse():
if book==[]:
print("Book stack is empty")
else:
top=len(book)-1
for i in range(top,-1,-1):
print(book[i])

while True:
print("1. Push")
print("2. Pop")
print("3.peek")
print("4. Traversal")
print("5. Exit")
ch=int(input("Enter your choice "))
if(ch==1):
push()
elif(ch==2):
pop()
elif(ch==3):
peek()
elif(ch==4):
traverse()
elif(ch==5):
print("End")
break
else:
print("Invalid choice")
Ex.no.14

Write a python program using function PUSH (Arr), where Arr is a list of numbers. From this
list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if
it has at least one element, otherwise display appropriate error message.

AIM:
To write a python program using function PUSH (Arr), where Arr is a list of numbers. From this
list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if
it has at least one element, otherwise display appropriate error message.

SOURCE CODE:

def push(Arr,item):
if item%5==0:
Arr.append(item)

def pop(Arr):
if Arr==[]:
print("No item found")
else:
print("The deleted element:")
return Arr.pop()

def show():
if Arr==[]:
print('No item found')
else:
top=len(Arr)-1
print("The stack elements are:")
for i in range(top,-1,-1):
print(Arr[i])

#Main program
Arr=[]
top=None
while True:
print('****** STACK IMPLEMENTATION USING LIST ******')
print('1: PUSH')
print('2: pop')
print('3: Show')
print('0: Exit')
ch=int(input('Enter choice:'))
if ch==1:
val=int(input('Enter no to push:'))
push(Arr,val)
elif ch==2:
res=pop(Arr)
print(res)
elif ch==3:
show()
elif ch==0:
print('Bye')
break
Output is:
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: pop
3: Show
0: Exit
Enter choice:1
Enter no to push:55
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: pop
3: Show
0: Exit
Enter choice:1
Enter no to push:33
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: pop
3: Show
0: Exit
Enter choice:2
The deleted element:
55
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: pop
3: Show
0: Exit
Enter choice:3
No item found
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: pop
3: Show
0: Exit
Enter choice:0
Bye
Ex.no.15

Write a python program to create a dictionary containing names and marks as key-value pairs of 5 students.
With separate user-defined functions to perform the following operations. Push the keys (name of the
student) of the dictionary into a stack, where the corresponding value (marks) is greater than 70.
Display the content of the stack.

SOURCE CODE:

def push(stk,d):
for i in d:
if d[i]>70:
stk.append(i)

def disp():
if stk==[]:
print("stack is empty")
else:
top=len(stk)-1
print(“The stack elements are;”)
for i in range(top,-1,-1):
print(stk[i])
stk=[]
d={}
print("performing stack operation using Dictionary")
while True:
print()
print("1.push")
print("2.disp")
print("0.exit")
opt=int(input("Enter your choice:"))
if opt==1:
d["Ramesh"]=int(input("Enter the mark of ramesh:"))
d["Umesh"]=int(input("Enter the mark of Umesh:"))
d["Vishal"]=int(input("Enter the mark of Vishal:"))
d["Khushi"]=int(input("Enter the mark of Khushi:"))
d["Ishika"]=int(input("Enter the mark of Ishika:"))
push(stk,d)
elif opt==2:
disp()
elif opt==0:
print('Bye')
break
OUTPUT:

Performing stack operation using Dictionary

1. push
2. disp
0. exit
Enter your choice:1
Enter the mark of ramesh: 55
Enter the mark of Umesh: 66
Enter the mark of Vishal: 77
Enter the mark of Khushi: 44
Enter the mark of Ishika: 88

1.push
2.disp
0.exit
Enter your choice:2
Ishika
Vishal

1.push
2.disp
0.exit
Enter your choice:0
Bye
>>>
EX.NO:16

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (display


Avgmarks greater than 75)

AIM:
To create a python program to integrate mysql with python to display the avgmarks
greater than 75

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SQL Table

Output:
EX.NO: 17 DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (INSERTING RECORDS

AND DISPLAYING RECORDS)

AIM:

To write a Python Program to integrate MYSQL with Python by inserting records to Emp
table and display the records.

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output:

SQL OUTPUT:
EX.NO: 18

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (SEARCHING AND

DISPLAYING RECORDS)

AIM:

To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and display the record if present in already existing table EMP, if not display the
appropriate message.

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output: RUN -1:

Run – 2:

SQL OUTPUT:

OUTPUT -1:

OUTPUT -2:
EX.NO: 19

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (UPDATING RECORDS)

AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and update the Salary of an employee if present in already existing table EMP, if not
display the appropriate message.
SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output: RUN -1:

Run -2:

SQL OUTPUT:
EX.NO: 20

DATE:

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON (DELETING RECORDS)

AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and delete the record of an employee if present in already existing table EMP, if not
display the appropriate message.

SOURCE CODE:

Result:

Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output: RUN -1:

RUN – 2:

SQL OUTPUT:
Sql exercise -1
a. To show all information about the students of the history department
b. To list the names of female students who are in hindi department.
c. To list the names of all the students with their date of admission in descending order.
d. To display the students name, age, fee, for male students only.
e. To count the number of students with age less than 20.

TABLE STUDENT

sno Name Age Dept Dateofadmin Fee gen


der
1. Panbaj 24 Computer 10/01/1999 120 M
2 Shalini 21 History 24/03/1998 200 F
3. Sanjay 20 Hindi 12/12/1996 300 M
4 Sudha 19 History 01/7/1999 400 F
5 Rakes 18 Hindi 05/09/1991 250 M
h
6 Shaku 19 History 27/06/1997 300 M
7 Surya 22 Computer 25/02/1997 210 M
8 Shika 23 Hindi 31/07/1997 200 f

Draw the table on left hand side


Answers
a. SELECT * from student where DEPT=”HISTORY”;
b. SELECT NAME FROM STUDENT WHERE GENDER =’F’ AND DEPT =’HINDI’;
c. SELECT NAME ,DATEOFADMIN FROM STUDENT ORDER BY DATEOFADMIN DESC;
d. SELECT NAME, FEE, AGE FROM STUDENT WHERE GENDER=’M’;
e. SELECT COUNT(*) FROM STUDENTS WHERE AGE<20;
sq1 Exercise-2
a. To display dcode and description of each classes in ascending order dcode.
b. to display the details of all the dresses which have launchdate in between 05-dec-07 to 20-
jun-08
c. To display the average price of all the dress which are made up of material with mcode as
M003.
d. To display material wise higher and latest price of dresses from dress table.
e. To display the description and type from table DRESS and MATERIAL.

TABLE DRESS
DCOD DESCRIPTIO PRIC MCOD LAUNCH
DATE
E N E E
10001 FORMAL 1250 M007 06-JUN-08
SHIRT
10020 FROCK 750 M004 06-SEPT-
07
10012 INFORMAL 1150 M002 06-JUN-08
SHIRT
10090 TULIP SHIRT 850 M003 31-MAR-
07
10019 EVENING 850 M003 20-OCT-08
GOWN
10023 PENCIL 1250 M003 20-OCT-08
SHIRT
10081 SLACHS 850 M003 09-MAR-
08
10007 FORMAL 1450 M001 20-OCT-08
PANT
10008 INFORMAL 1400 M002 07-APR-09
PANT
10024 BABY TOP 850 M003 06-JUN-08

TABLE MATERIAL
MCODE TYPE
M001 TERELENE
M002 COTTON
M003 POLYSTER
M004 SILK

ANSWERS.
A. SELECT DCODE, DESCRIPTION FROM DRESS ORDER BY DCODE;
B. SELECT * FROM DRESS WHERE LAUNCH DATE BETWEEN ’05-DEC-07’ AND ’20-JUN-08’

C. SELECT AVG(PRICE) FROM DRESS WHERE DCODE =”M003”;


D. SELECT MCODE, MAX(PRICE),MIN(PRICE)FROM DRESS GROUP BY MCODE;
E.SELECT DESCRIPTION, TYPE FROM DRESS D, MATERIAL WHERE D.CODE=M.CODE;
sq1 Exercise-3
a.) To display the details of those consumer whose address is delhi
b. To display the details of stationary whose price is in the range of 8 to 15.
c. To display the consumer name, address from table consumer and company and price from table
stationary with their corresponding matching S_ID.
d.) To increase the price of all the stationary by 2.
e. add a new record in consumer table with following details.
(17,”FAST WRITER”, “MUMBAI”,”GPO1”);

TABLE: STATIONARY
S_ID STATIONARY COMPANY PRICE
NAME
DP01 DET PEN ABC 10
PL02 PENCIL XYZ 6
ER05 ERASER XYZ 7
PL01 PENCIL CAN 5
GP02 GELPEN ABC 15

TABLE: CONSUMER
C_ID CONSUMER NAME ADDRESS S_ID
01 GOOD EARNER DELHI PL01
06 WHITE WELL MUMBAI GP02
12 TOPPER DELHI DP01
15 WRITE 4 DRAW DELHI PL02
16 MOTIVATION BANGALORE PL01

ANSWERS.
a.) SELECT * FROM CONSUMER WHERE ADDRESS=”DELHI”;
b.) SELECT * FROM STATIONARY WHERE PRICE BETWEEN 8 AND 15;
c.) SELECT CONSUMER NAME, ADDRESS ,COMPANY, PRICE FROM CONSUMER A,
STATIONARY B WHERE A.S_ID=B.S_ID;
d.) UPDATE STATIONARY SET PRICE=PRICE+2;
e.) INSERT INTO CONSUMER VALUES(17,”FAST WRITER”,”MUMBAI’,”GP01”);

You might also like