[go: up one dir, main page]

0% found this document useful (0 votes)
76 views44 pages

Practical No

The document contains 12 practical assignments completed by a student named Shivam Soni for their Computer Science class. Each practical has an objective, a Python code sample to achieve that objective, and sample output. The objectives include finding simple interest, checking divisibility, performing math operations using menus, printing exam results, finding factorials, sorting lists, and using functions with parameters and return values.

Uploaded by

Shivam Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views44 pages

Practical No

The document contains 12 practical assignments completed by a student named Shivam Soni for their Computer Science class. Each practical has an objective, a Python code sample to achieve that objective, and sample output. The objectives include finding simple interest, checking divisibility, performing math operations using menus, printing exam results, finding factorials, sorting lists, and using functions with parameters and return values.

Uploaded by

Shivam Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Practical No-01

Class : XII B Subject: Computer Science


Name : Shivam Soni Unit :Computational Thinking
and Programming
Date : Chapter : Getting Started with
Python
Remarks : Teacher’s sign :

Objective: To find Simple Interest using python


# Programme to find Simple Interest

p = float(input('Enter principle'))

r = float(input('Enter rate'))

t = float(input('Enter time'))

i=p*r*t/100

print("Interest=",i)

Output:
Enter principle22000

Enter rate15

Enter time8

Interest= 26400.0
Practical No – 02
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Flow of Control
Remarks : Teacher’s sign :

Objective: To check whether a number is divisible by 2 or 3

# Program to check whether a number is divisible by 2 or 3 using


nested if
num=float(input('Enter a number'))

if num%2==0:

if num%3==0:

print ("Divisible by 3 and 2")

else:

print ("divisible by 2 not divisible by 3")

else:

if num%3==0:

print ("divisible by 3 not divisible by 2")

else:

print ("not Divisible by 2 not divisible by 3")

Output:
Enter a number144
Divisible by 3 and 2
Practical No – 03
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Flow of Control
Remarks : Teacher’s sign :

Objective: To perform Mathematical operations using python

#. Menu based program to find sum, subtraction, #multiplication


and division of values.
print("1. Sum of two numbers")

print("2. Subtaction of two numbers")

print("3. Multiplication of two numbers")

print("4. Division of two numbers")

choice=int(input('Enter your choice'))

if choice==1 :

a=int(input('Enter first number'))

b=int(input('Enter second number'))

c=a+b

print("Sum=",c)

elif choice==2 :

a=int(input('Enter first number'))

b=int(input('Enter second number'))


c=a-b

print("Subtraction=",c)

elif choice==3 :

a=int(input('Enter first number'))

b=int(input('Enter second number'))

c=a*b

print("Multiplication=",c)

elif choice==4 :

a=int(input('Enter first number'))

b=int(input('Enter second number'))

c=a/b

print("Division=",c)

else :

print("Wrong choice")

Output:
1. Sum of two numbers

2. Subtaction of two numbers

3. Multiplication of two numbers

4. Division of two numbers

Enter your choice3

Enter first number567

Enter second number7865

Multiplication= 4459455
Practical No – 04
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Flow of Control
Remarks : Teacher’s sign :

Objective: To print result depending upon the percentage using


python

#Program to print result depending upon the percentage.


a=int(input('Enter your percentage'))

eligible= a>=33

compartment = a>=20 and a<33

fail=a<20

if eligible :

print("Pass");

elif compartment :

print("compartment");

elif fail:

print("Fail");

Output:
Enter your percentage578

Pass
Practical No – 05
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Flow of Control
Remarks : Teacher’s sign :

Objective: To find Factorial of a number using python

# Program to find factorial of a number.


n=eval(input("Enter a number="))

i=1

f=1

while i<=n:

f=f*i #1*2*3*4*5

i=i+1

print("Factorial of",n,"=",f)

Output:
Enter a number=57

Factorial of 57 =
405269195048772167556806019054323221349803847962266021451844812
80000000000000
Practical No – 06
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit :Computational
Thinking and Programming
Date : Chapter : LIST
Remarks : Teacher’s sign :

Objective: To sort values in a list using python

#Program to sort values in a list.


aList=eval(input(“Enter list:”))

print("Original List",aList)

n=len(aList)

for i in range(n-1):

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

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

aList[j],aList[j+1]=aList[j+1],aList[j]

print("Sorted List",aList)

Output:
Enter list:[34,65,23,67,54]

Original List [34, 65, 23, 67, 54]

Sorted List [23, 34, 54, 65, 67]


Practical No – 07
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : LIST
Remarks : Teacher’s sign :

Objective: To sort a sequence using insertion sort

#Program to sort a sequence using insertion sort.


aList =[15,6,13,22,3,52,2]

print("Original list is =",aList)

for i in range(1,len(aList)):

key=aList[i]

j=i-1

while j>=0 and key<aList[j]:

aList[j+1]=aList[j]

j=j-1

else:

aList[j+1]=key

print("list after sorting:",aList)

Output:
Original list is = [15, 6, 13, 22, 3, 52, 2]

list after sorting: [2, 3, 6, 13, 15, 22, 52]


Practical No – 08
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Working with
Functions
Remarks : Teacher’s sign :

Objective: To find largest number among two numbers

#Program to find largest among two numbers using a user defined

#function
def largest():

a=int(input("Enter first number="))

b=int(input("Enter second number="))

if a>b :

print ("Largest value="a)

else:

print ("Largest value="b)

largest()

Output:
Enter first number=67

Enter second number=76


Largest value=76
Practical No – 09
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Working with
Function
Remarks : Teacher’s sign :

Objective: To find Simple Interest using a user defined function

#Program to find simple interest using a user defined function with


parameters #and with return value.
def interest(p1,r1,t1 ):

i=p*r*t/100

return(i)

p=int(input("Enter principle="))

r=int(input("Enter rate="))

t=int(input("Enter time="))

in1=interest(p,r,t)

print("Interest=",in1)

Output:
Enter principle=76890

Enter rate=14
Enter time=9

Interest= 96881.4
Practical No – 10
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Working with
Functions
Remarks : Teacher’s sign :

Objective: To modify a list

#Program to pass a list as function argument and modify it.


def changeme( mylist,n ):

print ("inside the function before change ", mylist)

mylist[0]=n

print ("inside the function after change ", mylist)

return

list1 = eval(input("Enter list:"))

n=input("Enter value to mdify:")

ind=int(input("Enter index no which is to be modify:"))

print ("outside function before calling function", list1)

changeme( list1,n )

print ("outside function after calling function", list1)


Output:
Enter list:[78,95,45,67,65]

Enter value to mdify:63

Enter index no which is to be modify:3

outside function before calling function [78, 95, 45, 67, 65]

inside the function before change [78, 95, 45, 67, 65]

inside the function after change ['63', 95, 45, 67, 65]

outside function after calling function ['63', 95, 45, 67, 65]
Practical No – 11
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Working with
Functions
Remarks : Teacher’s sign :

Objective: To use default argument in a function

#Program to use default arguments in a function.


def printinfo( name, age = 35 ): #default argument

print ("Name: ", name)

print ("Age ", age)

return

name=input("Enter name:")

age=int(input("Enter age:"))

printinfo(name)

printinfo(name,age)

Output:
Enter name:'Ajay'

Enter age:56

Name: 'Ajay'

Age 35
Name: 'Ajay'

Age 56
Practical No – 12
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : File Handling
Remarks : Teacher’s sign :

Objective: To display the size of a file in different cases

# Program to display the size of a file after removing EOL


# characters, leading and trailing white spaces and blank lines.
Myfile =open(r'E:\poem.txt',"r")

Str1="" #initially storing a space (any non-None value)

size=0

tsize =0

while str1:

str1=myfile.readline()

tsize=tsize+len(Str1)

size=size+len(Str1.strip())

print("Size of file after removing all EOF characters and blank:",size)

print("The TOTAL size of the file:",tsize )

myfile.close()

Output:
Size of the file after removing all EOL characters & blank lines: 360
The total size of the file: 387
Practical No – 12
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : File Handling
Remarks : Teacher’s sign :

Objective: To sort details of students in a file

#Program to write roll numbers, names and marks of the

#students of a class(get from user) and sort these details in

# a file called “Marks.txt”.

count=int(input("How many students are there in the class?"))

fileout=open("Marks.txt","w")

for i in range(count):

print("Enter details for student",(i+1),"below")

rollno=int(input("Roll no:"))

name=input("Name:")

marks=float(input("marks:"))
rec=str(rollno)+","+name+","+str(marks)+'\n'

fileout.write(rec)

fileout.close()

Output:

How many students are there in the class?3

Enter details for student 1 below

Roll no:12

Name:Hazel

marks:67.75

Enter details for student 2 below

Roll no:15

Name:Jiya

marks:78.5

Enter details for student 3 below

Roll no:16

Name:Noor

marks:68.9
Practical No – 13
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : File Handling
Remarks : Teacher’s sign :

Objective: To read a text file line by line and display each words

#Write a program to read a text file line by line and display each
#word separated by a ‘#’.
Myfile=open("Answer .txt","r")

Line="" #initially storing a space (any non-None value)

While line:

Line=myfile.readline() #one line read from file

#printing the line word by word using split()

for word in line.split():

print(word,end=’#’)

print()

#close the file

Myfile.close()

Output:
Letter#’a’#is#a#wonderful#letter.#

It#is#impossible#to#think#of#a#sentence#without#it.#
Practical No – 14
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : File Handling
Remarks : Teacher’s sign :

Objective: To create a csvfile to store students data

# Ptogram to create a CSV file to store student data (Rollno., Name,


# Marks), obtain data from user and write 3 records into the file.
import csv

fh=open("Student.csv","w")

stuwriter=csv.writerow(fh)

stuwriter.writerow(['Rollno','Name','Marks'])

for i in range(5):

print("Student record",(i+1))

rollno=int(input("Enter rollno:"))

name=input("Enter name:")

marks=float(input("Enter marks:"))

sturec=[rollno,name,marks]

stuwriter.writerow(sturec)
fh.close() #close file

Output:
Student record 1

Enter rollno:11

Enter name: Nistha

Enter marks: 79

Student record 2

Enter rollno: 12

Enter name: Rudy

Enter marks: 89

Student record 3

Enter rollno: 13

Enter name: Rustom

Enter marks: 93
Practical No – 15
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Working with
Functions
Remarks : Teacher’s sign :

Objective:To traverse a linear list

#Program for traversing a linear list


def traverse(AR):

size =len(AR)

for i in range(size):

print(AR[i],end=' ')

#___________main___________

size=int(input("Enter the size of linear list to be input:"))

AR=[None]*size

print("Enter elements of the linear list ")

for i in range(size):

AR[i]=int(input("Element"+str(i)+":"))

print("traversing the list:")

traverse(AR)
Output:
Enter the size of linear list to be input:2

Enter elements of the linear list

Element0:23

Element1:45

traversing the list:

23 45
Practical No – 16
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Computational
Thinking and Programming
Date : Chapter : Data Structures
Remarks : Teacher’s sign :

Objecive: To implement stack operations

#Python program to implement stack operations.


############### STACK IMPLEMENTATION ###############

”””

Stack : implemented as a list

Top=integer having position of topmost element in stack

”””

def isEmpty(stk):

if stk==[]:

return True

else:

return False

def Push(stk,item):

stk.append(item)

top=len(stk)-1
def Pop(stk):

if isEmpty(stk):

return "Underflow"

else:

item=stk.pop()

if len(stk)==0:

top=len(stk)-1

return item

def Peek(stk):

if isEmpty(stk):

return "Underflow"

else:

top=len(stk)-1

return stk[top]

def Display(stk):

if isEmpty(stk):

print(“Stack empty”)

else:

top=len(stk)-1

print(stk[top])

for a in range(top-1,-1,-1):

print(stk[a])

#___main___
Stack=[]

top=None

while True:

print("STACK OPERATIONS")

print("1.Push")

print("2.Pop")

print("3.Peek")

print("4. Display stack")

print("5. Exit")

ch=int(input("Enter your choice (1-5):"))

if ch==1:

item=int(input("Enter item"))

Push(Stack,item)

elif ch ==2:

item=Pop(Stack)

if item=="Underflow":

print("Underflow! stack is empty!")

else:

print("Popped item is",item)

elif ch==3:

item=Peek(Stack)

if item =="Underflow":

print("Underflow! stack is empty!")


else:

print("Topmost item is" , item)

elif ch == 4:

Display(Stack)

elif ch==5:

break

else:

print("Invalid choice")

Output:
STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit

Enter your choice (1-5):1

Enter item6

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit
Enter your choice (1-5):1

Enter item8

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit

Enter your choice (1-5):1

Enter item2

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit

Enter your choice (1-5):1

Enter item4

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack
5. Exit

Enter your choice (1-5):4

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit

Enter your choice (1-5):3

Topmost item is 4

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit

Enter your choice (1-5):4

2
8

STACK OPERATIONS

1.Push

2.Pop

3.Peek

4. Display stack

5. Exit

Enter your choice (1-5):5


Practical No – 17
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Database Management
Date : Chapter : Simple Queries in
SQL
Remarks : Teacher’s sign :

Objective-SQL QUERIES
SQL 1

(i) Display the Mobile company, Mobile name & price in descending

order of their manufacturing date.


Ans. SELECT M_Compnay, M_Name, M_Price FROM MobileMaster

ORDER BY M_Mf_Date DESC;

(ii) List the details of mobile whose name starts with “S”.

Ans. SELECT * FROM MobileMaster

WHERE M_Name LIKE “S%‟;

(iii) Display the Mobile supplier & quantity of all mobiles except

“MB003‟.

Ans.SELECT M_Supplier, M_Qty FROM MobileStock

WHERE M_Id <>”MB003”;

(iv) To display the name of mobile company having price between 3000 &

5000.

Ans. SELECT M_Company FROM MobileMaster

WHERE M_Price BETWEEN 3000 AND 5000;

**Find Output of following queries

(v) SELECT M_Id, SUM(M_Qty) FROM MobileStock GROUP BY M_Id;

MB004 450

MB003 400

MB003 300
MB003 200

(vi) SELECT MAX(M_Mf_Date), MIN(M_Mf_Date) FROM MobileMaster;

2017-11-20 2010-08-21

(vii) SELECT M1.M_Id, M1.M_Name, M2.M_Qty, M2.M_Supplier

FROM MobileMaster M1, MobileStock M2 WHERE M1.M_Id=M2.M_Id

AND M2.M_Qty>=300;

MB004 Unite3 450 New_Vision

Classic Mobile
MB001 Galaxy 300
Store

(viii) SELECT AVG(M_Price) FROM MobileMaster;

5454
Practical No – 18
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Database Management
Date : Chapter : Simple Queries in
SQL
Remarks : Teacher’s sign :

Objective-SQL QUERIES

SQL 2
i. Display the Trainer Name, City & Salary in descending order of

theirHiredate.

Ans. SELECT TNAME, CITY, SALARY FROM TRAINER

ORDER BY HIREDATE;

ii. To display the TNAME and CITY of Trainer who joined the Institute in

the month of December 2001.

Ans. SELECT TNAME, CITY FROM TRAINER

WHERE HIREDATE BETWEEN „2001-12-01‟

AND „2001-12-31‟;

iii. To display TNAME, HIREDATE, CNAME, STARTDATE from

tables TRAINER and COURSE of all those courses whose FEES is less than

or equal to 10000.

Ans. SELECT TNAME,HIREDATE,CNAME,STARTDATE FROM TRAINER, COURSE

WHERE TRAINER.TID=COURSE.TID AND FEES<=10000;

iv. To display number of Trainers from each city.

Ans. SELECT CITY, COUNT(*) FROM TRAINER

GROUP BY CITY;

**Find Output of following queries

v. SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT IN(‘DELHI’,

‘MUMBAI’);
Practical No – 19
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Database Management
Date : Chapter : Simple Queries in
SQL
Remarks : Teacher’s sign :

Objective : SOL QUERIES

SQL 3
i) To display details of those Faculties whose salary is greater than 12000.

Ans: Select * from faculty

where salary > 12000;

ii) To display the details of courses whose fees is i n the range of 15000 to

50000 (both values included).

Ans: Select * from Courses

where fees between 15000 and 50000;

iii ) To increase the fees of all courses by 500 of “System Design” Course.

Ans: Update courses set fees = fees + 500

where Cname = “System Design”;

(iv) To display details of those courses which are taught by ‘Sulekha’ in

descending order of courses.

Ans: Select * from faculty,courses

where faculty.f_id = course.f_id and fac.fname = 'Sulekha'

order by cname desc;


Practical No – 20
Class : XII B Subject: Computer Science
Name : Shivam Soni Unit : Database Management
Date : Chapter : Simple Queries in SQL
Remarks : Teacher’s sign :

Objective: SQL QUERIES


SQL 4

(i) To display the records from table student in alphabetical order as per

the name of the student.

Ans. Select * from student

order by name;
(ii ) To display Class, Dob and City whose marks is between 450 and 551.

Ans. Select class, dob, city from student

where marks between 450 and 551;

(iii) To display Name, Class and total number of students who have

secured more than 450 marks, class wise

Ans. Select name,class, count(*) from student

group by class

having marks> 450;

(iv) To increase marks of all students by 20 whose class is “XII

Ans. Update student

set marks=marks+20

where class=‟XII‟;

You might also like