You are on page 1of 14

Dedraj Sewali Devi Todi D.A.V.-K.V.B.

School
Biratnagar (Morang)

Computer Science Assignment


Submitted By
KRISH KEDIA
Class: 12th (Science)

Under the Guidance of


Mr. Aashish Ashk
PGT (Computer Science)

Department of Computer Science


D.A.V- K.V.B. School, Biratnagar -13
Morang (Nepal)
Department of Computer Science
D.A.V- K.V.B. School, Biratnagar -13
Morang (Nepal)

CERTIFICATE

This is to certify that KRISH KEDIA


Of Class XII (Sci) has prepared the report on the Assignment. The Assignment is
the result of his efforts & endeavours. The report is found worthy of acceptance
as final Assignment report for the subject Computer Science (083) laid down in
the regulation of CBSE for the purpose of Practical Examination in Class XII to
be held in DAV School, Biratnagar on ______________.

He has prepared the project under my guidance.

(Mr. Aashish Ashk)


PGT (Computer Science)
Department of Computer Science
D.A.V- K.V.B. School, Brt -13
Morang (Nepal)

j dd
Department of Computer Science
D.A.V- K.V.B. School, Biratnagar -13
Morang (Nepal)

CERTIFICATE

The Assignment Report


Submitted by KRISH KEDIA of Class XII (Sci) for
the CBSE Senior Secondary Examination class XII of
Computer Science (083) at D.A.V - K.V.B School,
Biratnagar-13, Morang (Nepal) has been examined.

SIGNATURE OF EXAMINER
DATABASE MANAGEMENT SYSTEM

CREATE DATABASE:

USE DATABASE:

CREATE TABLE:

INSERT COMMAND:
SELECT COMMAND:

ALTER COMMAND (MODIFY ATTRIBUTE):


ALTER COMMAND (DROP ATTRIBUTE):

UPDATE COMMAND:
SORTING IN ASCENDING ORDER:

DELETE COMMAND TO REMOVE TUPLES:

GROUP BY (Finding MIN MAX)


15 Python Programs
1. FIND MAXIMUM OF TWO NUMBERS IN PYTHON:
def maximum(a, b):

if a >= b:
return a
else:
return b

# Driver code
a = 2
b = 4
print(maximum(a, b))

OUTPUT: 4
2. PYTHON PROGRAM FOR SIMPLE INTEREST:
def simple_interest(p,t,r):
print('The principal is', p)
print('The time period is', t)
print('The rate of interest is',r)

si = (p * t * r)/100

print('The Simple Interest is', si)


return si

# Driver code
simple_interest(8, 6, 8)

OUTPUT:
The principal is 8
The time period is 6
The rate of interest is 8
The Simple Interest is 3.84

3. PYTHON PROGRAM TO FIND THE FACTORIAL OF A 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))

OUTPUT:
Factorial of 5 is 120
4. PYTHON PROGRAM TO INTERCHANGE FIRST AND LAST ELEMENTS IN A
LIST:
def swapList(newList):
size = len(newList)

# Swapping
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp

return newList

# Driver code
newList = [12, 35, 9, 56, 24]

print(swapList(newList))

OUTPUT:
[24, 35, 9, 56, 12]

5. CHECK IF ELEMENT EXISTS IN LIST IN PYTHON:


lst=[ 1, 6, 3, 5, 3, 4 ]
#checking if element 7 is present
# in the given list or not
i=7
# if element present then return
# exist otherwise not exist
if i in lst:
print("exist")
else:
print("not exist")

OUTPUT:
not exist

6. REVERSING A LIST IN PYTHON:


def Reverse(lst):
new_lst = lst[::-1]
return new_lst

lst = [10, 11, 12, 13, 14, 15]


print(Reverse(lst))

OUTPUT:
[15, 14, 13, 12, 11, 10]
7. PYTHON PROGRAM TO MULTIPLY TWO MATRICES:
# take a 3x3 matrix
A = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]
# take a 3x4 matrix
B = [[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]
# result will be 3x4
result = [[sum(a * b for a, b in zip(A_row, B_col))
for B_col in zip(*B)]
for A_row in A]
for r in result:
print(r)

OUTPUT:
[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]

8. REVERSE WORDS IN A GIVEN STRING IN PYTHON:


# input string
string = "geeks quiz practice code"
# reversing words in a given string
s = string.split()[::-1]
l = []
for i in s:
# appending reversed words to l
l.append(i)
# printing reverse words
print(" ".join(l))

OUTPUT:
code practice quiz geeks

9. PYTHON PROGRAM TO PRINT EVEN LENGTH WORDS IN A STRING:


#input string
n="This is a python language"
#splitting the words in a given string
s=n.split(" ")
for i in s:
#checking the length of words
if len(i)%2==0:
print(i)

OUTPUT:
This
is
python
language
10. PYTHON PROGRAM TO FIND THE SUM OF ALL ITEMS IN A DICTIONARY:
# Function to print sum
def returnSum(myDict):
list = []
for i in myDict:
list.append(myDict[i])
final = sum(list)
return final
# Driver Function
dict = {'a': 100, 'b': 200, 'c': 300}
print("Sum :", returnSum(dict))

OUTPUT:
Sum : 600

11. PYTHON PROGRAM FOR MERGING TWO DICTIONARIES:


def Merge(dict1, dict2):
return(dict2.update(dict1))

# Driver code
dict1 = {'a': 10, 'b': 8}
dict2 = {'d': 6, 'c': 4}

# This returns None


print(Merge(dict1, dict2))

# changes made in dict2


print(dict2)
OUTPUT:
None
{'c': 4, 'a': 10, 'b': 8, 'd': 6}

12. FIND THE SIZE OF A TUPLE IN PYTHON:


import sys
# sample Tuples
Tuple1 = ("A", 1, "B", 2, "C", 3)
Tuple2 = ("Geek1", "Raju", "Geek2", "Nikhil", "Geek3", "Deepanshu")
Tuple3 = ((1, "Lion"), ( 2, "Tiger"), (3, "Fox"), (4, "Wolf"))
# print the sizes of sample Tuples
print("Size of Tuple1: " + str(sys.getsizeof(Tuple1)) + "bytes")
print("Size of Tuple2: " + str(sys.getsizeof(Tuple2)) + "bytes")
print("Size of Tuple3: " + str(sys.getsizeof(Tuple3)) + "bytes")

OUTPUT:
Size of Tuple1: 96bytes
Size of Tuple2: 96bytes
Size of Tuple3: 80bytes
13. PYTHON PROGRAM TO ORDER TUPLES BY LIST:
# initializing list
test_list = [('Gfg', 3), ('best', 9), ('CS', 10), ('Geeks', 2)]
# printing original list
print("The original list is : " + str(test_list))
# initializing order list
ord_list = ['Geeks', 'best', 'CS', 'Gfg']
# Order Tuples by List
# Using dict() + list comprehension
temp = dict(test_list)
res = [(key, temp[key]) for key in ord_list]
# printing result
print("The ordered tuple list : " + str(res))

OUTPUT:
The original list is : [('Gfg', 3), ('best', 9), ('CS', 10),
('Geeks', 2)]
The ordered tuple list : [('Geeks', 2), ('best', 9), ('CS', 10),
('Gfg', 3)]

14. PYTHON – FLATTEN TUPLE OF LIST TO TUPLE


# initializing tuple
test_tuple = ([5, 6], [6, 7, 8, 9], [3])
# printing original tuple
print("The original tuple : " + str(test_tuple))
# Flatten tuple of List to tuple
# Using sum() + tuple()
res = tuple(sum(test_tuple, []))
# printing result
print("The flattened tuple : " + str(res))

OUTPUT:
The original tuple : ([5, 6], [6, 7, 8, 9], [3])
The flattened tuple : (5, 6, 6, 7, 8, 9, 3)

15. PYTHON | WAYS TO REMOVE A KEY FROM DICTIONARY


# Initializing dictionary
test_dict = {"Arushi": 22, "Mani": 21, "Haritha": 21}
# Printing dictionary before removal
print("The dictionary before performing remove is : ", test_dict)
# Using del to remove a dict
# removes Mani
del test_dict['Mani']
# Printing dictionary after removal
print("The dictionary after remove is : ", test_dict)
# Using del to remove a dict
# raises exception
del test_dict['Mani']
OUTPUT:
The dictionary before performing remove is : {'Arushi': 22,
'Mani': 21, 'Haritha': 21}
The dictionary after remove is : {'Arushi': 22, 'Haritha':
21}

You might also like