Computer Science 12 A Practical File
Computer Science 12 A Practical File
ertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopa
sdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghj
COMPUTER SCIENCE 12 A
klzxcvbnmqwertyuiopasdfghjklz
PRACTICAL FILE
12/10/2022
xcvbnmqwertyuiopasdfghjklzxcv
NAMAN RAWAT
bnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwe
rtyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfg
KENDRIYA VIDYALAYA ITBP
CERTIFICATE
COMPUTER TEACHER:
EXTERNALEXAMINER:
PRINCIPAL
1) Write a program that generates a series using a
function which takes first and last values of the series
and then generates four terms that are equidistant e.g.,
if two numbers passed are 1 and 7 then function returns
1 3 5 7.
def ser( a , b ) :
d = int ( ( b - a ) / 3 )
print("Series = " , a , a + d , a + 2*d , b )
ser(first , last)
INPUT:
OUTPUT:
2) Write a program to find whether an inputted number
is perfect or not.
def perfect_number(n):
sum = 0
for x in range(1, n):
if n % x == 0:
sum += x
return sum == n
print(perfect_number(6))
INPUT:
OUTPUT:
3) Write a Program to find factorial of the entered
number.
def factorial(n):
# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
INPUT:
OUTPUT:
4) Write a python program to implement a stack using a
list data structure.
# Python program to
# demonstrate stack implementation
# using list
stack = []
print('Initial stack')
print(stack)
# pop() function to pop
# element from stack in
# LIFO order
print('\nElements popped from stack:')
print(stack.pop())
print(stack.pop())
print(stack.pop())
# uncommenting print(stack.pop())
# will cause an IndexError
# as the stack is now empty
INPUT:
OUTPUT:
5) To print even numbers in a list
# Python program to print even Numbers in a List
# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
OUTPUT:
6) Reverse words in a given String in Python
# Python code
# To reverse words in a given string
# input string
string = "MY NAME IS NAMAN RAWAT"
# reversing words in a given string
s = string.split()[::-1]
l = []
for i in s:
# apending reversed words to l
l.append(i)
# printing reverse words
print(" ".join(l))
INPUT:
OUTPUT:
7) Write a python script to take input for 2 numbers
calculate and print their sum, product and difference.
a=int(input("Enter 1st no "))
b=int(input("Enter 2nd no "))
s=a+b
p=a*b
if(a>b):
d=a-b
else:
d=b-a
print("Sum = ",s)
print("Product = ",p)
print("Difference = ",d)
INPUT:
OUTPUT:
8) Write a random number generator that generates
random numbers between 1 and 6 (simulates a dice).
import random
min = 1
max = 6
roll_again = "y"
while roll_again == "y" or roll_again == "Y":
print("Rolling the dice...")
val = random.randint (min, max)
print("You get... :", val)
roll_again = input("Roll the dice again? (y/n)...")
INPUT:
OUTPUT:
9) Write a python script to take input for 3 numbers, check and
print the largest number
OUTPUT:
10) Write a python script to Display Fibonacci Sequence Using
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
nterms = 10
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
Recursion
INPUT:
OUTPUT:
11) Write a program using function in python to check a
number whether it is prime or not.
# Program to check if a number is prime or not
num = 29
OUTPUT:
12) Given a list of numbers, write a Python program to
count Even and Odd numbers in a List..
# Python program to count Even
# and Odd numbers in a List
# list of numbers
list1 = [10, 21, 4, 45, 66, 93, 1]
even_count, odd_count = 0, 0
# checking condition
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
OUTPUT:
13) Python program to swap two elements in a list.
# Python program to swap elements
# at given positions
# Swap function
def swapPositions(list, pos1, pos2):
# Driver function
List = [23, 65, 19, 90]
pos1, pos2 = 1, 3
OUTPUT:
14) Remove multiple elements from a list in Python.
# Python program to remove multiple
# elements from a list
# creating a list
list1 = [14, 4, 18, 11, 5, 12]
OUTPUT:
15) Cloning or Copying a list.
# Python program to copy or clone a list
# Using the Slice Operator
def Cloning(li1):
li_copy = li1[:]
return li_copy
# Driver Code
li1 = [4, 8, 2, 10, 15, 18]
li2 = Cloning(li1)
print("Original List:", li1)
print("After Cloning:", li2)
INPUT:
OTPUT:
16) Break a list into chunks of size N in Python using a
loop.
my_list = [1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12]
start = 0
end = len(my_list)
step = 4
for i in range(start, end, step):
x=i
print(my_list[x:x+step])
INPUT:
OUTPUT:
17) Ways to find length of list.
Using Len()
# Python program to demonstrate working
# of len()
n = len([10, 20, 30])
print("The length of list is: ", n)
INPUT:
OUTPUT:
18) Python program to find Cumulative sum of a list.
# Python code to get the Cumulative sum of a list
def Cumulative(lists):
cu_list = []
length = len(lists)
cu_list = [sum(lists[0:x:1]) for x in range(0,
length+1)]
return cu_list[1:]
# Driver Code
lists = [1560, 4420, 2230, 400, 150]
print (Cumulative(lists))
INPUT:
OUTPUT:
19) Python program to interchange first and last
elements in a list.
# Python3 program to swap first
# and last element of a list
# Swap function
def swapList(newList):
size = len(newList)
# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
# Driver code
newList = [1882, 315, 89, 16, 20]
INPUT:
OUTPUT:
20) Python program to find second largest number in a
list.
# Python program to find largest number
# in a list
# List of numbers
list1 = [10, 20, 20, 45, 42, 47, 34, 98, 29]
OUTPUT:
MY SQL PROGRAMS
CREATE clause:
Procedure:
Create table (tablename) (column datatype, column’
datatype, column’ data))
INPUT:
OUTPUT:
INSERT clause:
PROCEDURE:
INSERT INTO (table_name) (column1, column2,
column3, ...)
VALUES (value1, value2, value3, ...);
INPUT:
OUTPUT:
SELECT clause:
PROCEDURE:
SELECT* from (table_name);
INPUT:
OUTPUT:
UPDATE clause:
PROCEDURE:
UPDATE (table_name) set(column’) where (column’’);
INPUT:
OUTPUT: