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

Computer Science Practical Class 12

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Computer Science Practical Class 12

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 123

SESSION: 2024-25

COMPUTER
Practical
SCIENCEFILE
SUBMITTED TO: SUBMITTED BY:
MR AJAY TOMAR Rajdeep Mishra
PGT (Computer Class12 A
Science)
Certificate

This is certified that Rajdeep Mishra of class XII


has successfully completed the Computer
Science Practical under my guidance in the
academic session 2024-25.

He has taken proper care and shown utmost


sincerity in completing his practicals.

I certify that this practical skill is up to my


expectations and as per the guidelines issued by
the Central Board of Secondary Education.

Mr. Ajay Tomar


(PGT Computer Science)
Acknowledgement

I would like to express my deep sense of


Thanks and Gratitude to my Computer Science
Educator Mr. Ajay Tomar for guiding me as well
as motivating me through the course of the
practicals. He always evinced keen interest in
my work. His constructive and constant
motivation helped me in successfully
completing my practicals.

My sincere thanks go to Ms. Gayatri


Shrivastav , the Principal of our school for
extending every possible support and
environment for completing my Computer
Science practicals.

Rajdeep Mishra
XII-A
Index
S.No. Programs Remark
1 Program 1:Write a Python Program to
add two numbers inputted by the user.

2 Program 2: Write a python program to check if


a Number is Odd or Even.
3 Program 3: Write a python program to solve
Quadratic equation.
4 Program 4: To swap values of two variables
without use of third variable.
5 Program 5: Python program to check if year is
a leap year or not.
6 Program 6: Python program to find the
factorial of a number provided by the user.
7 Program to display the Fibonacci sequence up
to n-th term.
8 Program 8 : Program to find HCF of two
numbers.
9 Program 9: Program to print calendar for the
given month and year.
10 Program 10: Program to check if the given
number is a palindrome or not.
11 Program 11: Program to check if the given
number is Armstrong or not.
12 Program 12: Program to find sum of series
1+x+x^2+x^3….x^n.
13 Porgram 13: Program to find sum of series 1!
+2!+3!+4!....n!.
14 Program 14: Write a python program to find
sum of series 1/1 + ½ + 1/3 …… 1/n
15 Program 15: Write a program to print the
following pattern
1
22
333…
16 Program 16: Write a program to make the
following sequence
1
12
123…
17 Program 17: Write a python program to print
the following sequence .
1
11
111…
18 Program 18: Write a program to print the
following sequence.
1111
222
33
4…
19 Program 19: Write a program to print
following pattern.
4444
333
22
1…
20 Program 20: Write a program to print
following pattern.
1
21
321…
21 Program 21: Write a program to print
following sequence.
*
**
***…
22 Program 22: Write a program to print full
pyramid using *.
23 Program 23: Write a python program of
connected inverted pyramid pattern of
numbers.
24 Program 24: Write a program to print even
number pyramid pattern.
25 Program 25: Write a program to print pattern
of horizontal tables.
26 Program 26: Write a program to print
pyramid pattern of alternate numbers.
27 Program 27: Write a program to convert
lowercase string to uppercase and vice versa.
28 Program 28: Write a program to count
alphabets , special symbols and numbers in
given string.
29 Program 29: Write a program to add to
matrices inputted by the user.
30 Program 30: Write a program to transpose a
matrix.
31 Program 31: Write a python program to use all
basic stack functions( push , pop , quit).
32 Program 32: Write a program to count and
display vowles in a string.
33 Program 33: Write a program to sort list of
numbers using bubble sort.
34 Program 34: Write a python program to sort
list of numbers using insertion sort.
35 Program 35: Write a program to copy
contents of first file to other.
36 Program 36: Write a program to count number
of frequencies of a word in a text file and
display it.
37 Program 37: Write a python program to count
number of vowels, lines and characters from
text stored in a file and display it.
38 Program 38: Write a program to read contents
from a text file and show it line wise on
screen.
39 Program 39: Aditi has used a text editing
software to type some text. After saving the
article as WORDS.TXT, she realised that she
has wrongly typed alphabet J in place of
alphabet I everywhere in the article. Write a
function definition for JTOI() in Python that
would display the corrected version of entire
content of the file WORDS.TXT with all the
alphabets "J" to be displayed as an alphabet
"I" on screen. Note: Assuming that WORD.TXT
does not contain any J alphabet otherwise.
40 Program 40: Write a program to count number
of times A and M appear in file F2.txt.
41 Program 41: Write a function in python to
read lines from file “POEM.txt” and display all
those words, which has two characters in it.
42 Program 42: Write a function that counts and
display the number of 5 letter words in a text
file “Sample.txt”.
43 Program 43: Write a function to display those
lines which start with the letter “G” from the
text file “MyNotes.txt”.
44 Program 44: Write a user defined function
countwords() to display the total number of
words present in the file from a text file
“Quotes.Txt”.
45 Program 45: Write a Python program to find
the number of lines in a text file ‘abc.txt’.
46 SQL Ques 1
47 SQL Ques 2
48 SQL Ques 3
49 SQL Ques 4
50 SQL Ques 5
51 SQL Ques 6
52 SQL Ques 7
53 SQL Ques 8
54 SQL Ques 9
55 SQL Ques 10
Program 1 : Write a Python Program to
add two numbers inputted by the user.

# This program adds two numbers


num1 = int(input("Enter a number:"))
num2 = int(input("Enter other number:"))
# Add two numbers
sum = num1 + num2
# Display the sum
print('The sum of ',num1,'and ',num2,'is
',sum)
Output:
Program 2 : Write a python program to
check if a Number is Odd or Even.

# Python program to check if the input


number is odd or even.
# A number is even if division by 2 gives a
remainder of 0.
# If the remainder is 1, it is an odd
number.
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
Output:
Program 3 : Write a python program to solve
Quadratic equation.

# Solve the quadratic equation ax**2 + bx


+c=0
# import complex math module
import cmath
a=1
b=5
c=6
# calculate the discriminant
d = (b**2) - (4*a*c)
# find two solutions
sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are {0} and
{1}'.format(sol1,sol2))
Output :
Program 4 : To swap values of two variables
without use of third variable.

x=5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)
Output:
Program 5 : Python program to check if year
is a leap year or not.

year = int(input("Enter a year: "))


# divided by 100 means century year (ending
with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
print("{0} is a leap year".format(year))
# not divided by 100 means not a century
year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
print("{0} is a leap year".format(year))
# if not divided by both 400 (century year)
and 4 (not century year)
# year is not leap year
else:
print("{0} is not a leap year".format(year))
Output:
Program 6 : Python program to find the
factorial of a number provided by the user.

num = int(input("Enter a number: "))


factorial = 1
# check if the number is negative, positive or
zero
if num < 0:
print("Sorry, factorial does not exist for
negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output:
Program 7 : Program to display the Fibonacci
sequence up to n-th term.

nterms = int(input("How many terms? "))


# first two terms
n1, n2 = 0, 1
count = 0
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
Output :
Program 8 : Program to find HCF of two
numbers.

# Python program to find H.C.F of two


numbers
# define a function
def compute_hcf(x, y):
# choose the smaller number
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
num1=int(input("Enter a number:"))
num2=int(input("Enter a number:"))
print("The H.C.F. is", compute_hcf(num1,
num2))
Output:
Program 9: Program to print calendar for the
given month and year.

# Program to display calendar of the given


month and year
# importing calendar module
import calendar
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))
# display the calendar
print(calendar.month(yy, mm))
Output:
Program 10: Program to check if the given
number is a palindrome or not.

num =int(input(“Enter a number:”))


temp = num
reverse = 0
while temp > 0:
remainder = temp % 10
reverse = (reverse * 10) + remainder
temp = temp // 10
if num == reverse:
print('Palindrome')
else:
print("Not Palindrome")
Output:
Program 11: Program to check if the given
number is Armstrong or not.

num = int(input("Enter a number: "))


# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output:
Program 12: Program to find sum of series
1+x+x^2+x^3….x^n.

def sum(x, n):


total = 1.0
multi = x
# First Term
print(1, end = " ")
# Loop to print the N terms
# of the series and find their sum
for i in range(1, n):
total = total + multi
print('%.1f' % multi, end = " ")
multi = multi * x
print('\n')
return total;
# Driver code
x = int(input(“Enter value for x :”))
n = int(input(“Enter value for n:”))
print('%.2f' % sum(x, n))
Output:
Porgram 13: Program to find sum of series
1!+2!+3!+4!....n!.

def factorial(N):
if (N == 1):
return 1
# Recursive Call
return N * factorial(N - 1)
# Function to find the sum of
# the series 1! - 2! + 3! - 4!
# + 5!... till the Nth term
def SeriesSum(N):
# Stores Required Sum
Sum = 0
# Loop to calculate factorial
# and sum them with their
# respective sign
for i in range(1, N + 1):
# Factorial of cur integer
fact = factorial(i);
# Stores the sign
sign = fact;
# If position is even sign
# must be negative
if (i % 2 == 0):
sign = sign * -1
# Adding value in sum
Sum += sign
# Return Answer
return Sum
# Driver Code
N = int(input(“Enter a number:”))
print(SeriesSum(N))
Output:
Program 14: Write a python program to find
sum of series.
1/1 + ½ + 1/3 …… 1/n

def sum(n):
i=1
s = 0.0
for i in range(1, n+1):
s = s + 1/i;
return s;

# Driver Code
n = int(input(“Enter a number:”
print("Sum is", round(sum(n), 6))
Output:
Program 15: Write a program to print the
following pattern .
1
22
333

depth =int(input(“Enter the required rows:”))

for number in range(depth):

for i in range(number):

print(number, end=" ")

print(" ")
Output:
Program 16: Write a program to make the
following sequence.

12

123

n = int(input("Enter number of rows: "))

for i in range(1,n+1):

for j in range(1, i+1):

print(j, end="")

print()
Output:
Program 17: Write a python program to print
the following sequence .

11

111

….

def pypart(n):

# outer loop to handle number of rows

# n in this case

for i in range(0, n):

for j in range(0, i+1):

print("1 ",end="")

print("\r")

n = int(input(“Enter number of rows:”))

pypart(n)
Output:
Program 18: Write a program to print the
following sequence.

1111

222

33

4…

rows = int(input(“Enter number of rows:”))

b=0

for i in range(rows, 0, -1):

b += 1

for j in range(1, i + 1):

print(b, end=' ')

print('\r')
Output:
Program 19: Write a program to print
following pattern.

4444

333

22

1…

rows = int(input("Enter number of rows:"))

for i in range(rows, 0, -1):

num = i

for j in range(0, i):

print(num, end=' ')

print("\r")
Output:
Program 20: Write a program to print
following pattern.

21

321…

rows = int(input("Enter number of rows:"))

for row in range(1, rows):

for column in range(row, 0, -1):

print(column, end=' ')

print("")
Output:
Program 21: Write a program to print
following sequence.

**

…..

def pypart(n):

# outer loop to handle number of rows

# n in this case

for i in range(0, n):

for j in range(0, i+1):

print("* ",end="")

print("\r")

n = int(input(“Enter number of rows:”))

pypart(n)
Output:
Program 22: Write a program to print full
pyramid using *.

rows = int(input("Enter number of rows: "))

k=0

for i in range(1, rows+1):

for space in range(1, (rows-i)+1):

print(end=" ")

while k!=(2*i-1):

print("* ", end="")

k += 1

k=0

print()
Output:
Program 23: Write a python program of
connected inverted pyramid pattern of
numbers.

rows = int(input("Enter number of rows:"))

for i in range(0, rows):

for j in range(rows - 1, i, -1):

print(j, '', end='')

for l in range(i):

print(' ', end='')

for k in range(i + 1, rows):

print(k, '', end='')

print('\n')
Output:
Program 24: Write a program to print even
number pyramid pattern.

rows =int(input("Enter number of rows:"))

LastEvenNumber = 2 * rows

evenNumber = LastEvenNumber

for i in range(1, rows+1):

evenNumber = LastEvenNumber

for j in range(i):

print(evenNumber, end=' ')

evenNumber -= 2

print("\r")
Output:
Program 25: Write a program to print pattern
of horizontal tables.

rows = int(input("Enter number of rows:"))

for i in range(0, rows):

for j in range(0, i + 1):

print(i * j, end=' ')

print()
Output:
Program 26: Write a program to print
pyramid pattern of alternate numbers.

rows = int(input("Enter number of rows:"))

i=1

while i <= rows:

j=1

while j <= i:

print((i * 2 - 1), end=" ")

j=j+1

i=i+1

print()
Output:
Program 27: Write a program to convert
lowercase string to uppercase and vice versa.

name = input("Enter a string:")

# converts lowercase to uppercase and vice


versa

print(name.swapcase())
Output:
Program 28: Write a program to count
alphabets , special symbols and numbers in
given string.

string = input("Enter the String: ")

alphabets = digits = special = 0

for i in range(len(string)):

if(string[i].isalpha()):

alphabets = alphabets + 1

elif(string[i].isdigit()):

digits = digits + 1

else:

special = special + 1

print("\nTotal Number of Alphabets in this


String: ", alphabets)
print("Total Number of Digits in this String: ",
digits)

print("Total Number of Special Characters in


this String: ", special)
Output:
Program 29: Write a program to add to
matrices inputted by the user.

matOne = []

print("Enter 9 Elements for First Matrix: ")

for i in range(3):

matOne.append([])

for j in range(3):

num = int(input())

matOne[i].append(num)

matTwo = []

print("Enter 9 Elements for Second Matrix: ")

for i in range(3):

matTwo.append([])

for j in range(3):
num = int(input())

matTwo[i].append(num)

matThree = []

for i in range(3):

matThree.append([])

for j in range(3):

matThree[i].append(matOne[i][j]+matTwo[i]
[j])

print("\nAddition Result of Two Given Matrix


is:")

for i in range(3):

for j in range(3):

print(matThree[i][j], end=" ")

print()
Output:
Program 30: Write a program to transpose a
matrix.

X = [[12,7],

[4 ,5],

[3 ,8]]

result = [[0,0,0],

[0,0,0]]

# iterate through rows

for i in range(len(X)):

# iterate through columns

for j in range(len(X[0])):

result[j][i] = X[i][j]

for r in result:

print(r)
Output:
Program 31: Write a python program to use
all basic stack functions( push , pop , quit).

class Stack:

def __init__(self):

self.items = []

def is_empty(self):

return self.items == []

def push(self, data):

self.items.append(data)

def pop(self):

return self.items.pop()

s = Stack()

while True:

print('push <value>')
print('pop')

print('quit')

do = input('What would you like to do?


').split()

operation = do[0].strip().lower()

if operation == 'push':

s.push(int(do[1]))

elif operation == 'pop':

if s.is_empty():

print('Stack is empty.')

else:

print('Popped value: ', s.pop())

elif operation == 'quit':

break
Output:
Program 32: Write a program to count and
display vowles in a string.

def Check_Vow(string, vowels):

final = [each for each in string if each in


vowels]

print(len(final))

print(final)

# Driver Code

string = input("Enter a string:")

vowels = "AaEeIiOoUu"

Check_Vow(string, vowels);
Output:
Program 33: Write a program to sort list of
numbers using bubble sort.

def bubbleSort(arr):

n = len(arr)

# optimize code, so if the array is already


sorted, it doesn't need

# to go through the entire process

swapped = False

# Traverse through all array elements

for i in range(n-1):

# range(n) also work but outer loop will

# repeat one time more than needed.

# Last i elements are already in place

for j in range(0, n-i-1):


# traverse the array from 0 to n-i-1

# Swap if the element found is greater

# than the next element

if arr[j] > arr[j + 1]:

swapped = True

arr[j], arr[j + 1] = arr[j + 1], arr[j]

if not swapped:

# if we haven't needed to make a


single swap, we

# can just exit the main loop.

return

# Driver code to test above

arr = [64, 34, 25, 12, 22, 11, 90]

bubbleSort(arr)

print("Sorted array is:")


for i in range(len(arr)):

print("% d" % arr[i], end=" ")


Output:
Program 34: Write a python program to sort
list of numbers using insertion sort.

def insertionSort(arr):

n = len(arr) # Get the length of the array

if n <= 1:

return # If the array has 0 or 1 element,


it is already sorted, so return

for i in range(1, n): # Iterate over the array


starting from the second element

key = arr[i] # Store the current element


as the key to be inserted in the right position

j = i-1

while j >= 0 and key < arr[j]: # Move


elements greater than key one position ahead
arr[j+1] = arr[j] # Shift elements to
the right

j -= 1

arr[j+1] = key # Insert the key in the


correct position

# Sorting the array [12, 11, 13, 5, 6] using


insertionSort

arr = [12, 11, 13, 5, 6]

insertionSort(arr)

print(arr)
Output :
Program 35: Write a program to copy
contents of first file to other.

# open both files

with open('F1.txt','r') as firstfile,


open('F2.txt','a') as secondfile:

# read content from first file

for line in firstfile:

# append content to second file

secondfile.write(line)

Output:
Program 36: Write a program to count
number of frequencies of a word in a text file
and display it.

word = "contents"

count = 0

with open("F1.txt", 'r') as f:

for line in f:

words = line.split()

for i in words:

if(i==word):

count=count+1

print("Occurrences of the word", word, ":",


count)
Output:
Program 37: Write a python program to count
number of vowels, lines and characters from
text stored in a file and display it.

def counting(filename):

# Opening the file in read mode

txt_file = open(filename, "r")

# Initialize three variables to count number


of vowels,

# lines and characters respectively

vowel = 0

line = 0

character = 0

# Make a vowels list so that we can


# check whether the character is vowel or
not

vowels_list = ['a', 'e', 'i', 'o', 'u',

'A', 'E', 'I', 'O', 'U']

# Iterate over the characters present in file

for alpha in txt_file.read():

# Checking if the current character is


vowel or not

if alpha in vowels_list:

vowel += 1

# Checking if the current character is

# not vowel or new line character

elif alpha not in vowels_list and alpha !=


"\n":

character += 1
# Checking if the current character

# is new line character or not

elif alpha == "\n":

line += 1

# Print the desired output on the console.

print("Number of vowels in ", filename, " =


", vowel)

print("New Lines in ", filename, " = ", line)

print("Number of characters in ", filename,


" = ", character)

# Calling the function counting which gives


the desired output

counting('F1.txt')
Output:
Program 38: Write a program to read contents
from a text file and show it line wise on
screen.

def read_file():

file = open("F2.txt","r")

for line in file:

print(line, end="")

file.close()

read_file()
Output:
Program 39: Aditi has used a text editing
software to type some text. After saving the
article as WORDS.TXT, she realised that she
has wrongly typed alphabet J in place of
alphabet I everywhere in the article.
Write a function definition for JTOI() in Python
that would display the corrected version of
entire content of the file WORDS.TXT with all
the alphabets "J" to be displayed as an
alphabet "I" on screen.
Note: Assuming that WORD.TXT does not
contain any J alphabet otherwise.

def JTOI():

file = open("words.txt","r")

data = file.read()

for letter in data:

if letter == 'J':

print("I",end="")

else:

print(letter,end="")

file.close()

JTOI()
Output:
Program 40: Write a program to count
number of times A and M appear in file F2.txt.

def AMcount():

file = open('F2.txt','r')

data = file.read()

counta=0

countm=0
for letter in data:

if letter == 'A' or letter =='a':

counta += 1

elif letter == 'M' or letter =='m':

countm += 1

file.close()

print('A or a:',counta'and M or m:',countm)

AMcount()
Output:
Program 41: Write a function in python to
read lines from file “POEM.txt” and display all
those words, which has two characters in it.

def TwoCharWord():

f = open('poem.txt')

count = 0

for line in f:
words = line.split()

for w in words:

if len(w)==2:

print(w,end=' ')

f.close()

Output:
Program 42: Write a function that counts and
display the number of 5 letter words in a text
file “Sample.txt”.

def count_words( ):

c=0

f = open("Sample.txt")

line = f.read()

word = line.split()

for w in word:

if len(w) == 5:

c += 1

print(c)

f.close()
Output:
Program 43: Write a function to display those
lines which start with the letter “G” from the
text file “MyNotes.txt”.

def count_lines( ):

c=0

f = open("MyNotes.txt")

line = f.readlines()

for w in line:

if w[0] == 'G':

print(w)

f.close()
Output :
Program 44: Write a user defined function
countwords() to display the total number of
words present in the file from a text file
“Quotes.Txt”.

def countwords():

s = open("Quotes.txt","r")

f = s.read()

z = f.split ()

count = 0

for i in z:

count = count + 1

print ("Total number of words:", count)


Output:
Program 45: Write a Python program to find
the number of lines in a text file ‘abc.txt’.

f=open("abc.txt","r")

d=f.readlines()

count=len(d)

print(count)

f.close()
Output:
SQL Ques 1:

Display Output :

i) SELECT COUNT (*) , CITY FROM STUDENT


GROUP BY CITY HAVING COUNT(*)>1;

ii) SELECT MAX(DOB,MIN(DOB) FROM


STUDENT;

Ans:

i)

ii)
SQL Ques 2:

Write queries to :

i) To display CNO, CNAME, TRAVELDATE from


the table TRAVEL in descending order of CNO.

ii) To display the CNAME of all customers


from the table TRAVEL who are travelling by
vechicle with code Vo1 or Vo2.

Answers :
i) SELECT CNO , CNAME, TRAVELDATE FROM
TRAVEL ORDER BY CNO DESC;

ii) SELECT CNAME FROM TRAVEL VCODE IN


(‘V01’, ‘V02’);

SQL Ques 3:
Write queries to:

i) To display NO, NAME, TDATE from the table


TRIP in descending order of NO.

ii) To display the NAME of the drivers from the


table TRIP who are traveling by transport
vehicle with code 101 or 103.

Answers :

i) SELECT NO, NAME, TDATE FROM TRIP

ORDER BY NO;

ii) SELECT NAME FROM TRIP WHERE TCODE =


101 OR TCODE = 103;

SQL Ques 4: Write SQL query to add a


column total price with datatype numeric and
size 10, 2 in a table product.
Answer: ALTER TABLE PRODUCT ADD TOTAL
PRICE NUMBER (10,2).

SQL Ques 5: Sonal needs to display name of


teachers, who have “0” as the third character
in their name. She wrote the following query.

SELECT NAME FROM TEACHER WHERE NAME


= “$$0?”;

But the query isn’t producing the result.


Identify the problem.

Answer: The wildcards are incorrect. The


corrected query is SELECT NAME FROM
TEACHER WHERE NAME LIKE ‘_ _0%’.
SQL Ques 6: Deepika wants to remove all
rows from the table BANK. But he needs to
maintain the structure of the table. Which
command is used to implement the same?

Answer: DELETE FROM BANK.

SQL Ques 7: While creating table ‘customer’,


Rahul forgot to add column ‘price’. Which
command is used to add new column in the
table. Write the command to implement the
same.

Answer: ALTER TABLE CUSTOMER ADD PRICE


NUMBER (10, 2).
SQL Ques 8 :

Write queries to :
i) To display those company name which are
having prize less than 30000.
ii) To display the name of the companies in
reverse alphabetical order.

Answers :
i) SELECT NAME FROM COMPANY WHERE
COMPANY.CID=CUSTOMER. CID AND
PRICE < 30000;
ii) SELECT NAME FROM COMPANY ORDER BY
NAME DESC;

SQL Ques 9:

Write queries to:


i) To display TEACHERNAME, PERIODS of all
teachers whose periods are more than 25.
ii) To display all the information from the
table SCHOOL in descending order of
experience.
Answers:
i) SELECT TEACHERNAME, PERIODS
FROM SCHOOL WHERE PERIODS>25:
ii) SELECT * FROM SCHOOL;

SQL Ques 10:


Write queries to:

i) TO DISPLAY ALL THE DETAILS OF THOSE


WATCHES WHOSE NAME ENDS WITH ‘TIME’

ii) TO DISPLAY WATCH’S NAME AND PRICE OF


THOSE WATCHES WHICH HAVE PRICE RANGE
IN BE-TWEEN 5000-15000.
Answers :

i) SELECT * FROM WATCHES WHERE


WATCH_NAME LIKE ‘%TIME’

(Vi mark for SELECT query) (Vi mark for where


clause)

ii) SELECT WATCH_NAME, PRICE WATCH


WHERE PRICE BETWEEN 5000 AND 15000;

(Vi mark for SELECT query) (Vz mark for


where clause)

You might also like