Practical File Removed-1
Practical File Removed-1
PRACTICAL FILE
for
AISSCE 2024 Examination
[As a part of the Computer Science Course (083)]
Submitted by:
……………………… ………………………….
Signature of Internal Examiner Signature of External Examiner
CERTIFICATE
……….…………………
Signature of Principal
………………………………… …………………………………..
1. Arithmetic Operations
2 Perfect Number
3 Armstrong Number
4 Palindrome number
5 List Operations
6 Floyd’s Triangle
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:
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)
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
modify_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
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")
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: