Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
96 views

Computer Science 12 A Practical File

The document appears to be a certificate certifying that a student named NAMAN RAWAT has successfully completed their Computer Science (New - 083) practical file. It includes their name, class, school/institution name, and is signed by a computer teacher and external examiner. The certificate is dated 12/10/2022.

Uploaded by

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

Computer Science 12 A Practical File

The document appears to be a certificate certifying that a student named NAMAN RAWAT has successfully completed their Computer Science (New - 083) practical file. It includes their name, class, school/institution name, and is signed by a computer teacher and external examiner. The certificate is dated 12/10/2022.

Uploaded by

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

qwertyuiopasdfghjklzxcvbnmqw

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

This is to certify that NAMAN RAWAT


student of Class- XII Science has
successfully completed their
Computer Science (New - 083)
Practical File.

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 )

first = int(input("Enter first Term = "))


last = int(input("Enter last Term = "))

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):

# single line to find factorial


return 1 if (n==1 or n==0) else n * factorial(n - 1);

# 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 = []

# append() function to push


# element in the stack
stack.append('a')
stack.append('b')
stack.append('c')

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())

print('\nStack after elements are popped:')


print(stack)

# 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]

# using list comprehension


even_nos = [num for num in list1 if num % 2 == 0]

print("Even numbers in the list: ", even_nos)


INPUT:

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

a=int(input("Enter 1st no "))


b=int(input("Enter 2nd no "))
c=int(input("Enter 3rd no "))
if(a>b and a>c):
m=a
else:
if(b>c):
m=b
else:
m=c
print("Max no = ",m)
INPUT:

OUTPUT:
10) Write a python script to Display Fibonacci Sequence Using

#Python program to display the Fibonacci sequence

def recur_fibo(n):

if n <= 1:

return n

else:

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

nterms = 10

#check if the number of terms is valid

if (nterms <= 0):

print("Plese enter a positive integer")

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

# To take input from the user


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

# define a flag variable


flag = False

# prime numbers are greater than 1


if num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
flag = True
# break out of loop
break

# check if flag is True


if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
INPUT:

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

# iterating each number in list


for num in list1:

# checking condition
if num % 2 == 0:
even_count += 1
else:
odd_count += 1

print("Even numbers in the list: ", even_count)


print("Odd numbers in the list: ", odd_count)
INPUT:

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):

list[pos1], list[pos2] = list[pos2], list[pos1]


return list

# Driver function
List = [23, 65, 19, 90]
pos1, pos2 = 1, 3

print(swapPositions(List, pos1-1, pos2-1))


INPUT:

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]

# Iterate each element in list


# and add them in variable total
for ele in list1:
if ele % 2 == 0:
list1.remove(ele)

# printing modified list


print("New list after removing all even numbers: ", list1)
INPUT:

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]

# Removing duplicates from the list


list2 = list(set(list1))

# Sorting the list


list2.sort()

# Printing the second last element


print("Second largest element is:", list2[-2])
INPUT:

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:

You might also like