Xii STD CS Practical Manual
Xii STD CS Practical Manual
2. In Practical exams, the question paper will have two questions with internal choice.
Total 20 Marks
INDEX
Question Page
Sl. No. Program Name
Number Number
(a) Calculate Factorial
1 PY1 2
(b) Sum of Series
(a) Odd or Even
2 PY2 2
(b) Reverse the String
3 PY3 Generate values and remove odd numbers 3
4 PY4 Generate Prime numbers and Set Operations 4
5 PY5 Display a String elements – Using Class 4
6 DB6 MySQL – Employee Table 5
7 DB7 MySQL – Student Table 7
8 PY8 Python with CSV 9
9 PY9 Python with SQL 10
10 PY10 Python Graphics with Pip 11
1
PY1(a)- Calculate Factorial
QUESTION:
Write a program to calculate the factorial of the given number using for loop.
AIM:
To write a program to calculate the factorial of the given number using for loop.
CODING:
num=int(input("Enter a Number:"))
fact=1
for i in range(1,num+1):
fact=fact*i
print("Factorial of ", num," is ",fact)
Output:
Enter a Number:12
Factorial of 12 is 479001600
RESULT:
Using a python program calculated the factorial of the given number with the help of for loop.
AIM:
To write a python program to sum the given series.
CODING:
n=int(input("Enter a value of n: "))
s=0.0
for i in range(1,n+1):
a=float(i**i)/i
s=s+a
print("The sum of the series is: ",s)
OUTPUT:
Enter a value of n: 4
The sum of the series is 76.0
RESULT:
Using a python program calculated the sum of given series.
AIM:
To write a python program using functions to check whether a number is even or odd.
CODING:
def oddeven(a):
if(a%2==0):
return 1
else:
return 0
num=int(input("Enter a number: "))
if(oddeven(num)==1):
print("The given number is Even")
else:
2
print("The given number is Odd")
OUTPUT:
Enter a number: 7
The given number is Odd
Enter a number: 6
The given number is Even
RESULT:
With the help of a python program using functions checked whether a number is even or odd.
AIM:
To Write a python program to create a mirror of the given string.
CODING:
def rev(str1):
str2=''
i =len(str1)-1
while i>=0:
str2+=str1[i]
i-=1
return str2
word=input("Enter a String:")
print("\n The Mirror image of the given string is:",rev(word))
OUTPUT:
Enter a String: school
The mirror image of the given string is: loohcs
RESULT:
Using a python program created a mirror of the given string.
AIM:
To Write a python program to generate values from 1 to 10 and then remove all the odd numbers from the list.
CODING:
num1=[]
for i in range(1,11):
num1.append(i)
print("Numbers from 1 to 10.....\n",num1)
for j,i in enumerate(num1):
if(i%2==1):
del num1[j]
print("The values after removed odd numbers....\n",num1)
OUTPUT:
Numbers from 1 to 10….
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
The values after removed odd numbers….
[2, 4, 6, 8, 10]
3
RESULT:
Using a python program generated values from 1 to 10 and then removed all the odd numbers from the list.
AIM:
To write a python program that generates a set of prime numbers and another set of odd numbers and to display the
result of union, intersection, difference and symmetric difference operations.
CODING:
odd = set([(x*2)+1 for x in range(0,5)])
primes=set()
for i in range(2,10):
j=2
f=0
while j<=i/2:
if i%j==0:
f=1
break
j+=1
if f==0:
primes.add(i)
print("Odd Numbers:",odd)
print("Prime Numbers:",primes)
print("Union:",odd.union(primes))
print("Intersection:",odd.intersection(primes))
print("Difference:",odd.difference(primes))
print("Symmetric Difference:",odd.symmetric_difference(primes))
OUTPUT:
Odd Numbers: {1, 3, 5, 7, 9}
Prime Numbers: {2, 3, 5, 7}
Union: {1, 2, 3, 5, 7, 9}
Intersection: {3, 5, 7}
Difference: {1, 9}
Symmetric Difference: {1, 2, 9}
RESULT:
Using a python program generated a set of prime numbers and another set of odd numbers and displayed the result of
union, intersection, difference and symmetric difference operations.
AIM:
To write a python program to accept a string and print the number of uppercase, lowercase, vowels, consonants and
spaces in the given string using class.
CODING:
class String:
def __init__(self):
self.uppercase=0
self.lowercase=0
self.vowels=0
4
self.consonants=0
self.spaces=0
self.string=""
def getstr(self):
self.string=str(input("Enter a String: "))
def count_upper(self):
for ch in self.string:
if(ch.isupper()):
self.uppercase+=1
def count_lower(self):
for ch in self.string:
if(ch.islower()):
self.lowercase+=1
def count_vowels(self):
for ch in self.string:
if(ch in ('A','a','E','e','I','i','O',’o’,'U','u')):
self.vowels+=1
def count_consonants(self):
for ch in self.string:
if(ch not in ('A','a','E','e','I','i','O',’o’,'U','u',’ ‘)):
self.consonants+=1
def count_space(self):
for ch in self.string:
if (ch==" "):
self.spaces+=1
def execute(self):
self.count_upper()
self.count_lower()
self.count_vowels()
self.count_consonants()
self.count_space()
def display(self):
print("The given string contains......")
print("%d Uppercase letters"%self.uppercase)
print("%d lowercase letters"%self.lowercase)
print("%sVowels "%self.vowels)
print("%d Consonants"%self.consonants)
print(“%d Spaces “%self.spaces)
S=String()
S.getstr()
S.execute()
S.display()
OUTPUT:
Enter a String: Welcome to Computer Science
The given string contains...
3 Uppercase letters
21 Lowercase letters
10 Vowels
14 Consonants
3 Spaces
RESULT:
Using a python program accepted a string and printed the number of uppercase, lowercase, vowels, consonants and
spaces in the given string using class.
QUESTION:
5
Create an employee Table with the fields empno, empname, desig, dept, age and place. Enter five records into the table
• Add two more records to the table.
• Modify the table structure by adding one more field namely date of joining.
• Check for Null value in doj of any record.
• List the employees who joined after 2018/01/01.
AIM:
To create an employee table with the given fields, to enter five records into the table and to do the given
manipulations.
SQL QUERIES:
(i)Creating Database db:
RESULT:
Using MYSQL created an employee Table with the given fields and entered five records into the table and manipulated.
SQL QUERIES:
(i)Creating Database db:
RESULT:
Using MYSQL, created student table, entered the given data and executed given queries.
AIM:
To write a program using python to get 10 player names and their scores, to write the above data into a csv file and to
search a player in the csv file.
CODING:
import csv
with open('d:\\pyprg\\player.csv','w') as f:
w = csv.writer(f)
n=1
while (n<=10):
name = input("Player Name?:" )
score = int(input("Score: "))
w.writerow([name,score])
n+=1
print("Player File created")
f.close()
9
searchname=input("Enter the name to be searched ")
f=open('d:\\pyprg\\player.csv','r')
reader =csv.reader(f)
lst=[]
for row in reader:
lst.append(row)
q=0
for row in lst:
if searchname in row:
print(row)
q+=1
if(q==0):
print("string not found")
f.close()
OUTPUT:
Player Name?:Rohit Sharma
Score: 264
Player Name?:VirenderSehwag
Score: 219
Player Name?:Sachin Tendulkar
Score: 200
Player Name?:Dhoni
Score: 190
Player Name?:Sachin Tendulkar
Score: 250
Player Name?:ViratKohli
Score: 148
Player Name?:Ganguly
Score: 158
Player Name?:KapilDev
Score: 175
Player Name?:Amarnath
Score: 148
Player Name?:SunilGavaskar
Score: 200
Player File created
Enter the name to be searched Sachin Tendulkar
['Sachin Tendulkar', '200']
['Sachin Tendulkar', '250']
RESULT:
Using a python program, with the help of a csv file, stored 10 player names and scores and searched for a
particular player in the csv file.
AIM:
To create a sql table using python, store 10 names and age and to sort the table in descending order of age and
display.
CODING:
import sqlite3
connection = sqlite3.connect("info.db")
cursor = connection.cursor()
#cursor.execute("DROP Table student")
10
cursor.execute("create table student(name, age)")
print("Enter 10 students names and their ages respectively:")
for i in range(10):
who =[input("Enter Name:")]
age =[int(input("Enter Age:"))]
n =len(who)
for i in range(n):
cursor.execute("insert into student values (?, ?)", (who[i],age[i]))
cursor.execute("select * from student order by age desc")
print("Displaying All the Records From student Table in Descending order of age")
print (*cursor.fetchall(),sep='\n' )
OUTPUT:
Enter 10 students names and their ages respectively:
Enter Name:Annamalai
Enter Age:17
Enter Name:Aashik Mathew
Enter Age:23
Enter Name:Kumaran
Enter Age:30
Enter Name:Sivasakthiya
Enter Age:28
Enter Name:Leena
Enter Age:45
Enter Name:Meena
Enter Age:65
Enter Name:Kamalakannan
Enter Age:35
Enter Name:Sowmyaa
Enter Age:20
Enter Name:Ramaa
Enter Age:70
Enter Name:Melvin
Enter Age:35
Displaying All the Records From student Table in Descending order of age
('Ramaa', 70)
('Meena', 65)
('Leena', 45)
('Kamalakannan', 35)
('Melvin', 35)
('Kumaran', 30)
('Sivasakthiya', 28)
('Aashik Mathew', 23)
('Sowmyaa', 20)
('Annamalai', 17)
RESULT:
Using python program, created a sql table, stored 10 names and their age and sorted the table in descending
order of age and displayed.
AIM:
To write a python program to get 5 marks using list and to display the marks in pie chart.
CODING:
import matplotlib.pyplot as plt
marks=[]
i=0
11
subjects = ["Tamil", "English", "Maths", "Science", "Social"]
while i<5:
marks.append(int(input("Enter Mark = ")))
i+=1
for j in range(len(marks)):
print("{}.{} Mark = {}".format(j+1, subjects[j],marks[j]))
plt.pie (marks, labels = subjects, autopct = "%.2f ")
#plt.axes().set_aspect ("equal")
plt.show()
OUTPUT:
Enter Mark = 67
Enter Mark = 31
Enter Mark = 45
Enter Mark = 89
Enter Mark = 73
1.Tamil Mark = 67
2.English Mark = 31
3.Maths Mark = 45
4.Science Mark = 89
5.Social Mark = 73
RESULT:
Using a python program got 5 marks using list and displayed the marks in pie chart.
INTERNAL CHOICES
12