Sei sulla pagina 1di 30

KENDRIYA VIDYALAYA GANGTOK

Computer Science Practical


For

AISSCE 2020 Examination


[As a part of the Computer Science Course (083)]

Submitted by:

Name: Munendra Thakur

Roll No.: 16638674

Under the Guidance of:

Mr. Rameshwar Raj

PGT (Comp.Sc), K.V. Gangtok


CERTIFICATE

This is to certify that the Report entitled Computer Science

Practical is a bonafide work done by Munendra Thakur of class XII

Session 2019-20 in partial fulfillment of CBSE’s AISSCE Examination

2020 and has been carried out under my direct supervision and

guidance.

This report or a similar report on the topic has not been

submitted for any other examination and does not form a part of any

other course undergone by the candidate.

Signature of External Teacher Signature of teacher

Signature of Principal

(Mr. Rameshwar Raj)


ACKNOWLEDGEMENT

I undertook this Project work, as the part of my XII-Computer

Science course. I had tried to apply my best of knowledge and

experience, gained during the study and class work experience.

However, developing software system is generally a quite complex and

time-consuming process. It requires a systematic study, insight vision

and professional approach during the design and development.

Moreover, the developer always feels the need, the help and good

wishes of the people near you, who have considerable experience and

idea.

I would like to extend my sincere thanks and gratitude to my

teacher Mr.Rameshwar Raj. I am very much thankful to our Principal

Mr.Rameshwar Raj for providing valuable infrastructure, moral

support which encourages me to develop this project in better way.


I would like to take the opportunity to extend my sincere thanks

and gratitude to my parents for being a source of inspiration and

providing time and freedom to develop this software project.

I also feel indebted to my friends for the valuable suggestions

during the project work.

Practical – I

Program that reads a string and checks whether it is a palindrome


string or not.

Code :

string=input(“Enter a string :”)

length=len(string)

mid=length/2

rev=-1

for a in range(mid) :

if string[a]==string[rev] :
a += 1

rev -= 1

else :

print(string,”is not a palindrome”)

break

else :

print(string,”is a palindrome”)

Practical – II

Program that receives two numbers in a function and returns of all


arithmetic operations (+,-,*,/,%) on these numbers.

Code :

def arCalc(x,y) :

Return x+y, x-y, x*y, x/y, x%y


num1=int(imput(“Enter number 1 :”))

num2=int(input(“Enter number 2 :”))

add, sub, mult, div, mod=arCalc(num1,num2)

print(“Sum of given numbers :”, add)

print(“Subtraction of given numbers :”, sub)

print(“Product of given numbers :”, mult)

print(“Division of given numbers :”, div)

print(“Modulo of given numbers :”, mod)

Output :

Sample run –

Enter number 1 : 13

Enter number 2 : 7

Sum of given numbers : 20

Subtraction of given numbers : 6

Product of given numbers :91

Division of given numbers : 1.8571428571428572

Modulo of given numbers : 6

Practical – III
To generate a random integer number in range 15 to 35.

Code :

>>> print(random.randint(15,35))

Output :

16 (The output generated is integer between range 15 to 35)


Practical – IV

To display the size of a file in bytes.

Code :

myfile=open(r’E:\poem.txt’,”r”)

str=myfile.read()

size=len(str)

print(“Size of the given file poem.txt is ”)

print(size,“bytes”)

Output :

>>> Size of the given file poem.txt is 387 bytes


Practical – V

Creating a file to hold some data , separated as lines.

Code :

fileout=open(“Student1.txt”,”w”)

for i in range(5) :

name=input(“Enter name of a student :”)

fileout.write(name)

fileout.write(‘\n’)

fileout.close()

Output :

Sample Run -
>>> Enter name of a student : Java

>>> Enter name of a student : Jivin

>>> Enter name of a student : Jonathan

>>> Enter name of a student : JJagjeet

>>> Enter name of a student : Javed

Java

Jivin

Jonathan

Jagjeet

Javed

Practical – VI

To calculate factorial using recursion.

Code ;

def fact(n) :

if n < 2 :

return 1

return n* fact(n-1)
n=int(input(“Enter a number(>0):”))

print(“Factorial of”,n,“is”,fact(n))

Output ;

Sample Run –

>>> Enter a number (>0) : 4

Factorial of 4 is 24

>>> Enter a number (>0) : 5

Factorial of 5 is 120

Practical – VII

Program using a recursive function to print Fibonacci series upto nth


term.
Code :

def fib(n) :

if n == 1 :

return 0

elif n == 2 :

return 1

else :

return fib(n-1) + fib(n-2)

n=int(input(“Enter last term required :”))

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

print(fib(i),end=’,’)

print(“…”)

Output :

>>> Enter last term required : 8

0, 1, 2, 3, 5, 8, 13, …
Practical – VIII

To draw a bar chart using pyplot.

Code :
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

objects = ('Python', 'C++', 'Java', 'Perl', 'Scala',


'Lisp')
y_pos = np.arange(len(objects))
performance = [10,8,6,4,2,1]

plt.bar(y_pos, performance, align='center', alpha=0.5)


plt.xticks(y_pos, objects)
plt.ylabel('Usage')
plt.title('Programming language usage')

plt.show()

Output :
Practical – IX

To draw a pie chart using pyplot.

Code :
import matplotlib.pyplot as plt

# Data to plot
labels = 'Python', 'C++', 'Ruby', 'Java'
sizes = [215, 130, 245, 210]
colors = ['gold', 'yellowgreen', 'lightcoral',
'lightskyblue']
explode = (0.1, 0, 0, 0) # explode 1st slice

# Plot
plt.pie(sizes, explode=explode, labels=labels,
colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)

plt.axis('equal')
plt.show()

Output :
Practical – X

To draw a line chart using pyplot.

Code :
import matplotlib.pyplot as plt

# line 1 points

x1 = [1,2,3]

y1 = [2,4,1]

# plotting the line 1 points

plt.plot(x1, y1, label = "line 1")

# line 2 points
x2 = [1,2,3]

y2 = [4,1,3]

# plotting the line 2 points

plt.plot(x2, y2, label = "line 2")

# naming the x axis

plt.xlabel('x - axis')

# naming the y axis

plt.ylabel('y - axis')

# giving a title to my graph

plt.title('Two lines on same graph!')

# show a legend on the plot

plt.legend()

# function to show the plot

plt.show()

Output :
Practical – XI
Program which depicts push & pop operation in stack.

Code :

# Python code to demonstrate Implementing

# stack using list

stack = ["Amar", "Akbar", "Anthony"]

stack.append("Ram")

stack.append("Iqbal")

print(stack)

print(stack.pop())

print(stack)

print(stack.pop())

print(stack)

Output :

['Amar', 'Akbar', 'Anthony', 'Ram', 'Iqbal']


Iqbal
['Amar', 'Akbar', 'Anthony', 'Ram']
Ram
['Amar', 'Akbar', 'Anthony']
Practical – XII

Program which depicts push & pop operation in queue.

Code :

# Python code to demonstrate Implementing

# Queue using deque and list

from collections import deque

queue = deque(["Ram", "Tarun", "Asif", "John"])

print(queue)

queue.append("Akbar")

print(queue)

queue.append("Birbal")

print(queue)

print(queue.popleft())

print(queue.popleft())

print(queue)

Output :
deque(['Ram', 'Tarun', 'Asif', 'John'])
deque(['Ram', 'Tarun', 'Asif', 'John', 'Akbar'])
deque(['Ram', 'Tarun', 'Asif', 'John', 'Akbar', 'Birbal'])
Ram
Tarun
deque(['Asif', 'John', 'Akbar', 'Birbal'])

Practical – XIII

Program for recursive binary search.

Code :
def binarySearch (arr, l, r, x):

if r >= l:

mid = l + (r – l)/2

if arr[mid] == x:

return mid

elif arr[mid] > x:

return binarySearch(arr, l, mid-1, x)

else:

return binarySearch(arr, mid+1, r, x)

else:

return -1
arr = [ 2, 3, 4, 10, 40 ]

x = 10

result = binarySearch(arr, 0, len(arr)-1, x)

if result != -1:

print “Element is present at index %d” % result

else:

print “Element is not present in array”

Output :

Element is present at index 3

Practical – XIV

Python program that displays first three rows fetched from


student table of MySQL database “test’.

Code :

Import mysql.connector as sqltor

Mycon=sqltor.connect(host=”localhost”,user=”learner”,passwd=
”fast”,database=”test”)
if mycon.is_connected()==False :

print(‘Error connecting to MySQL database’)

cursor=mycon.cursor()

cursor.execute(“select*from student”)

data=cursor.fetchmany(3)

count=cursor.rowcount

for row in data :

print(row)

mycon.close()

Output :

(101,’Ruhani’, Decimal(‘76.80’),’A’,’A’,”Pending”)

(102,’George’, Decimal(‘71.20’),’B’,’A’,”Submitted”)

(103,’Simran’, Decimal(’81.20’),’A’,’B’,”Evaluated”)

Practical – XV

Write a recursive function to print a string backward.


Code :

def reverse(string):

if len(string) == 0:

return

temp = string[0]

reverse(string[1:])

print(temp, end='')

string = "Geeks for Geeks"

reverse(string)

Output :

skeeG rof skeeG


Practical – VI

Write a program to calculate the cube of given numbers using


python.

Code :
# Python Program to Calculate Cube of a Number

def cube(num):
return num * num * num

number = float(input(" Please Enter any numeric Value :


"))

cub = cube(number)

print("The Cube of a Given Number {0} =


{1}".format(number, cub))

Output :
Practical – XVII

Program to find GCD or HCF of two numbers.

Code :

def gcd(a,b):
if (a == 0):
return b
if (b == 0):
return a
if (a == b):
return a
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)
a = 98
b = 56
if(gcd(a, b)):
print('GCD of', a, 'and', b, 'is', gcd(a, b))
else:
print('not found')

Output :
GCD of 98 and 56 is 14

Practical – XVIII
Program that inpuits an integer 0-999 and then prints if the integer
entered is a 1/2/3 digit number.

Code:
num=int(input(“Enter a number(0..999):”))

if num < 0 :

print(“Invalid entry.Valid range is 0 to 999.”)

elif num < 10 :

print(“Single digit number is entered”)

elif num < 100 :


print(“Two digit number is entered”)

elif num <= 999 :

print(“Three digit number is entered”)

else :

print(“Invalid entry.Valid range is 0 to 999.”)

Output :
Sample run –

>>> Enter a number (0..999) : -3

Invalid entry. Valid range is 0 to 999.

>>> Enter a number (0..999) : 4

Single digit number is entered

>>> Enter a number (0..999) : 100

Three digit number is entered

>>> Enter a number (0..999) : 10

Two digit number is entered

>>> Enter a number (0..999) : 3000

Invalid entry. Valid range is 0 to 999.

Practical – XIX

Queries on given table.

GCODE GNAME SIZE COLOUR PRICE


111 TShirt XL Red 1400.00
1122 Jeans L Blue 1600.00
113 Skirt M Black 1100.00
114 Ladies Jacket XL Blue 4000.00
115 Trousers L Brown 1500.00
116 Ladies Top L Pink 1200.00

• Display those garments that are available in XL size.


Code :
select GNAME
from GARMENT
where SIZE= ’XL’ ;
• Display codes and names of those garments that have their names starting with
“Ladies”
Code :
select GCODE , GNAME
from GARMENT
where GNAME like ’Ladies%’ ;
• Display garment names , codes and prices of those garments that have price in the
range 1000.00 to 1500.00.
Code :
select GNAME,GCODE,PRICE
from GARMENT
where PRICE BETWEEN 1000.00 AND 1500.00 ;
• To change the colour of garment with code as 116 to “Orange”
Code :
UPDATE GARMENT
set COLOUR=’Orange’
where GCODE= 116

Practical – XX
Queries on given table.

DRINKCODE DNAME PRICE CALORIES


101 Lime and Lemon 20.00 120
102 Apple Drink 18.00 120
103 Nature Nectar 15.00 115
104 Green Mango 15.00 140
105 Aam Panna 20.00 135
106 Mango Juice Bahaar 12.00 150

• Display names and drink codes of those drinks that have more than 120
calories.
Code :
select DNAME<DRINKCODE
from SOFTDRINK
where CALORIES > 120 ;
• Display drink codes, names and calories of all drinks in descending order of
calories.
Code :
select DRINKCODE , DNAME,CALORIES
from SOFTDRINK
order by CALORIES desc ;
• Display names and prices of drinks that have price in the range 12 to 18.
Code :
select DNAME,PRICE
from SOFTDRINK
where PRICE BETWEEN 12 AND 18 ;
• Increase the price of all drinks in the given table by 10 %
Code :
UPDATE SOFTDRINK
set PRICE = PRICE + 0.10 * PRICE ;

Practical – XXI
Queries on given table.

GCODE GNAME SIZE COLOUR PRICE


111 Bag XL Red 1400.00
1122 Gloves L Blue 1600.00
113 Sunglasses M Black 1100.00
114 Knee Pad XL Blue 4000.00
115 Handkerchief III Brown 1500.00
116 Purse III Pink 1200.00

• Display those quipments that are available in XL size.


Code :
select GNAME
from EQUIPS
where SIZE= ’XL’ ;
• Display codes and names of those equipments that have their names starting with
“Purse”
Code :
select GCODE , GNAME
from EQUIPS
where GNAME like ’Purse%’ ;
• Display equipments names , codes and prices of those equipments that have price in
the range 1000.00 to 1500.00.
Code :
select GNAME,GCODE,PRICE
from EQUIPS
where PRICE BETWEEN 1000.00 AND 1500.00 ;
• To change the colour of equipment with code as 116 to “Orange”
Code :
UPDATE EQUIPS
set COLOUR=’Orange’
where GCODE= 116 ;

Potrebbero piacerti anche