Kovaipudur, Coimbatore – 641042
Affiliation No: 1930510
PRACTICAL FILE
for
AISSCE 2024 Examination
[As a part of the Computer Science Course (083)]
Submitted by:
Name of the Student : RISHIE V
[Reg No. ___________]
Under the Guidance of:
Teacher’s Name: MS. AKHILA
PGT (CSc)
……………………… ………………………….
Signature of Internal Examiner Signature of External Examiner
CERTIFICATE
Certified that this is the bonafide record of the practical
work in Computer Science done by RISHIE V (Reg No:
____________) and is submitted for the Practical
Examination at CS Academy, Coimbatore on
_____________________.
……….…………………
Signature of Principal
(Mr. Neil Guha)
………………………………… …………………………………..
Signature of Internal Examiner Signature of External Examiner
INDEX
S No TOPIC
1. Arithmetic Operations
2 Perfect Number
3 Armstrong Number
4 Palindrome number
5 List Operations
6 Floyd’s Triangle
7 Modifying elements of a List
8 Counting the Number of Odd and Even Number in a Tuple
9 Counting the Number of Vowels in a String
10 Random number between 100 and 1000
11 Counting the occurrence of “my”
12 Counting Number of Digits, Upper-Case and Lower-Case
13 Creating and Reading a Binary file
14 Searching for a record in a Binary file
15 Creating CSV to enter Product Details
16 Stack Operations
17 Vowels in a String Using Stacks
18 Queries in SQL
EX 1. Arithmetic operation
AIM:
To write a program to perform arithmetic operations
CODING:
CS=True
while CS:
print("Functions available: \n 1)Add \n 2)Subtract \n 3)Multiply \n
4)Divide \n 5)Exponent")
F=int(input('Enter your desired function:'))
if F==1:
n1=float(input('Enter number 1:'))
n2=float(input('Enter number 2:'))
print(n1+n2)
elif F==2:
n1=float(input('Enter number 1:'))
n2=float(input('Enter number 2:'))
print(n1-n2)
elif F==3:
n1=float(input('Enter number 1:'))
n2=float(input('Enter number 2:'))
print(n1*n2)
elif F==4:
n1=float(input('Enter number 1:'))
n2=float(input('Enter number 2:'))
print(n1/n2)
elif F==5:
n1=int(input('Enter base:'))
n2=int(input('Enter exponent'))
print(n1**n2)
else:
print('Enter a valid input')
continue
CS=int(input('Do you want to continue(1. Yes / 0. No)?'))
print('Thank You')
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 2: Perfect Number or Not
AIM:
To write a program to find whether the given number is a perfect number
or not.
CODING:
num = int(input("Enter a number: "))
cs = 0
for i in range (1, num):
if num % i == 0:
cs += i
if cs==num:
print(num," is a perfect number.")
else:
print(num," is not a perfect number.")
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 3: Armstrong Number or Not
AIM:
To write a program to check whether the given number is
armstrong number or not.
CODING:
num = int(input("Enter a number: "))
temp = num
n=len(str(temp))
armstrong_sum = 0
while temp > 0:
digit = temp % 10
armstrong_sum += digit ** n
temp //= 10
if armstrong_sum==num:
print(num, "is an Armstrong number.")
else:
print(num, "is not an Armstrong number.")
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 4. Palindrome number or not
AIM:
To write a program to check whether the given number is
palindrome or not.
CODING:
n=int(input('Enter a number:'))
temp=n
cs=''
while n>0:
r=str(n%10)
cs+=r
n=n//10
if temp==int(cs):
print('Congratulations it is a palindrome')
else:
print('Not a palindrome')
if temp==int(cs):
print('Congratulations it is a palindrome')
else:
print('Not a palindrome')
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 5: LIST METHODS
AIM:
To write a program to Enter a list of strings and apply all the methods
applicable to lists.
CODING:
# Taking input from the user to create a list of strings
L = input("Enter a list of strings (separated by spaces): ")
lst=L.split()
print("Original List:", lst)
# Length of the list
print("Length of the list:", len(lst))
# Accessing elements using indexing
i = int(input("Enter an index to access an element: "))
if 0 <= i < len(lst):
print("Element at index", i, "is:", lst[i])
else:
print("Invalid index")
# Slicing (Extracting a portion of the list)
start = int(input("Enter the starting index for slicing: "))
end = int(input("Enter the ending index for slicing: "))
print("Sliced list:", lst[start:end])
# Appending an element to the list
n = input("Enter an element to append to the list: ")
lst.append(n)
print("List after appending:", lst)
# Count occurrences of an element in the list
c = input("Enter an element to count occurrences: ")
count = lst.count(c)
print("Number of occurrences:", count)
# Removing an element from the list
s = input("Enter an element to remove from the list: ")
if s in lst:
lst.remove(s)
print("List after removing:", lst)
else:
print("Element not found in the list")
# Popping an element from the list
i = int(input("Enter an index to pop from the list: "))
if 0 <= i < len(lst):
p = lst.pop(i)
print("Element popped:", p)
print("List after popping:", lst)
else:
print("Invalid index for pop")
# Deleting an element from the list using del
i = int(input("Enter an index to delete from the list: "))
if 0 <= i < len(lst):
del lst[i]
print("List after deleting:", lst)
else:
print("Invalid index for delete")
# Sorting the list
lst.sort()
print("Sorted list:", lst)
# Reversing the list
lst.reverse()
print("Reversed list:", lst)
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 5: Floyd’s Triangle
AIM:
To write a program to print the Floyd’s triangle
CODING:
row=int(input("Enter the number of rows:"))
num=1
for i in range(row):
for j in range(i+1):
print(num,end=" ")
num=num+1
print()
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 7: Write a python program to pass a list to a function and
double the odd values and half even values of a list and display list
elements after changing.
AIM:
To Write a python program to pass a list to a function and double the odd values
and half even values of a list and display list elements after changing.
CODING:
def modify_list(lst):
for i in range(len(lst)):
if lst[i] % 2 == 0:
lst[i] //= 2
else:
lst[i] *= 2
lst=eval(input("Enter a list of integers:"))
print("Original List:", lst)
modify_list(lst)
print("Modified List:", lst)
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 8: Write a Python program input n numbers in tuple and pass
it to function to count how many even and odd numbers are
entered.
AIM:
To write a program to count number of odd and even numbers in a tuple
CODING:
L=eval(input('Enter a tuple of numbers:'))
def even(x):
if x%2==0:
return True
else:
return False
ce=co=0
for i in L:
if even(i):
ce+=1
else:
co+=1
print('Odd numbers=',co)
print('Even numbers=',ce)
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 9: Write a Python program to pass a string to a function and count
how many vowels present in the string.
AIM:
To write a program to count the number of vowels in a given string.
CODING:
def cv(s):
vowels = "aeiouAEIOU"
count = 0
for char in s:
if char in vowels:
count += 1
return count
string = input("Enter a string: ")
print("Number of vowels in the string:", cv(string))
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 10: Random Number between 100 and 1000
AIM:
To write a program to generate a random number between 100 and 1000
CODING:
import random
C=True
while C==True:
random_number = random.randint(100, 1000)
print("Random number between 100 and 1000:", random_number)
C=int(input("Do you want to continue(1.Yes/0.No)"))
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 11: Count the number of times the word “my” has
occurred in the given text file.
AIM:
To write a program to count the number of times the word “my” has
occurred in the given text file.
CODING:
fh=open('Sample.txt')
x=fh.read()
L=x.split()
c=L.count('my')
print('Number of times the word my has occured is:',c)
OUTPUT:
RESULT:
The above program was executed and the result has been obtained.
EX 12: Count the number of digits and uppercase letters in a text file.
AIM:
To write a program to count the number of digits and uppercase letters in
a text file.
CODING:
fh=open('Sample.txt')
cn=0
cu=0
x=fh.read()
L=x.split()
for i in L:
for j in i:
if i.isdigit():
cn+=1
elif i.isupper():
cu+=1
print('Number of digits:',cn)
print('Number of uppercase characters:',cu)
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 13: Create and read a binary file
AIM:
To write a program to enter Student no, name and marks of three subjects
until the user ends of a student using a binary file and to read a file.
CODING:
import pickle
def createbinary():
fh=open("StuRec.bin","wb")
C=True
while C==True:
D={}
N=input("Enter name of student")
No=int(input("Enter roll number of student"))
M1=int(input("Enter marks of Subject 1:"))
M2=int(input("Enter marks of Subject 2:"))
M3=int(input("Enter marks of Subject 3:"))
D['Name']=N
D['Roll Number']=No
D['Mark1']=M1
D['Mark2']=M2
D['Mark3']=M3
pickle.dump(D,fh)
C=int(input("Do you want to continue(1.Yes/0.No)?"))
fh.close()
def readbinary():
fh=open("StuRec.bin","rb")
while True:
try:
data=pickle.load(fh)
print(data)
except EOFError:
break
#main{}
createbinary()
readbinary()
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 14: Search for a record in a binary file.
AIM:
To write a program to open file stu.dat and search for records with roll no
as 12 and 24. If found, display the records.
CODING:
import pickle
def searchrec(fh):
flag=0
c=0
while True:
try:
data=pickle.load(fh)
if data['Roll Number']==12 or data['Roll Number']==24:
print(data)
flag=1
c+=1
except EOFError:
break
if flag==0:
print('No such record with roll number 12 or 24')
else:
print('Number of records with roll number 12 or 24=',c)
fh=open('StuRec.bin','rb')
searchrec(fh)
OUTPUT:
RESULT:
The above program was executed and the output has been obtained.
EX 15: Creating a CSV file to enter the product details
AIM:
To write a program to create a csv file and enter product details
CODING:
import csv
fh=open("ProductDetails.csv","w",newline='')
cwriter=csv.writer(fh)
n=int(input("Number of products:"))
for i in range(n):
L=eval(input("Enter product details in a list:"))
cwriter.writerow(L)
fh.close()
OUTPUT:
RESULT:
The above program was executed and the output has been obtained
EX 16: Stack Operations
AIM:
To write a program to perform stack operations.
CODING:
L = []
def push(item):
L.append(item)
print("Pushed", item, "into the stack.")
def pop():
if not isempty():
popped_item = L.pop()
print("Popped", popped_item, "from the stack.")
return popped_item
else:
print("Stack is empty. Cannot perform pop.")
return None
def isempty():
return len(L) == 0
def display():
if not isempty():
print("Stack contents:")
for item in reversed(L):
print(item)
else:
print("Stack is empty. Nothing to display.")
def main():
while True:
print("\nSelect an operation:")
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Exit")
choice = int(input("Enter your choice (1/2/3/4): "))
if choice == 1:
item = input("Enter the item to push into the stack: ")
push(item)
elif choice == 2:
pop()
elif choice == 3:
display()
elif choice == 4:
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
main()
OUTPUT:
RESULT:
The above program was executed and the output has been obtained
EX 17 VOWELS IN A STRING USING STACK
AIM:
Write a program to print the vowels in a string using stacks concept
CODING:
S=input("Enter a string:")
def push():
for i in S:
if i in 'aeiouAEIOU':
L.append(i)
def pop():
l=len(L)
print("no of vowels",l)
x=L.pop()
print(L)
L=[]
push()
pop()
OUTPUT:
RESULT:
The above program was executed and the result has been obtained.
EX 18 QUERIES IN SQL
AIM:
To create a table ‘Student’ and execute queries.
CODING:
i) Display records of students who have scored more than 90 in Math:
ii) Display the records of students whose name starts with A:
iii) Display records of students whose fourth letter is E:
iv) Display records by arranging names in descending order
v) Increase the mark by 2 in Physics for students who secured 80:
vi) Display the set of students who reside only in Coimbatore:
vii) Change the size of column of ‘Name’ field from 20 to 40:
viii) Display the Total Mark and Average in Math:
ix) Display the record with maximum marks in Physics:
x) Write a command to delete a record from the table:
xi) Write a command to drop the table:
xii) Show the list of databases:
xiii) Write a command to show the list of tables in a database:
xiv) Write a command to describe the structure of the table:
RESULT:
The above queries were executed and the output has been obtained.