Computer Science Lab Mannual
Computer Science Lab Mannual
lab manual
aissce (2023-24)
Submitted to: Submitted by:
MR. RAVENDRA SINGH students name
Class-xii
Roll NO.
Sr.No Name of the Experiment Page.
No
1
10
11
12
13
14
15
16
17
18
19
20
21
Program. 1 #write a program to print cubes of numbers in the range 15 to 20.
print("is", i**3)
Output::
Program. 2 #write a program that multiplies two integer number without using the * operator
using repeated addition.
product= 0
count= n1
while count>0:
count= count-1
product= product+n2
Output::
Program.3 # Program that receives two numbers in a function and returns the results of all
arithmetic operations (+,-,*,%) on these numbers
#_main
Output::
Program.4 Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it
then returns the amount converted to rupees. Create the function in both void and non-void
forms.
def void_dollar_to_rupee(dollar):
r=dollar*76.22
def non_void_dollar_to_rupee(dollar):
return dollar*76.22
void_dollar_to_rupee(d)
Output::
Program.5 Write a function that receives two numbers and generates a random number from
that range. Using function the main should be able to print three numbers randomly.
import random
def random_num(x,y):
return random.randint(x,y)
print("Random No.1:",random_num(n1,n2))
print("Random No.2:",random_num(n1,n2))
print("Random No.3:",random_num(n1,n2))
Output::
Program.6 . Write a python program using a function to print Fibonacci series up to n numbers
def fibo():
a=0
b=1
temp=0
for i in range(0,n):
temp = a + b
b=a
a= temp
fibo()
Output::
Program.7. Read a file line by line and print it.
# writing to file
file1.writelines(L)
file1.close()
# Using readlines()
Lines = file1.readlines()
count = 0
count += 1
Output::
Program.8 Read a text file and display the number of vowels /consonants / uppercase /
lowercase characters in the file.
vowel_count=0
consonants_count=0
vowel = set("aeiouAEIOU")
if alphabet in vowel:
vowel_count=vowel_count +1
consonants_count=consonants_count
else:
consonants_count=consonants_count+1
uppercase_count=0
lowercase_count=0
if elem.isupper():
uppercase_count += 1
elif elem.islower():
lowercase_count += 1
Output::
Program.9. Write a Program to enter the string and to check if it’s palindrome or not using loop.
def isPalindrome(input_str):
return False
return True
Output::
def fibo():
a=0
b=1
temp=0
for i in range(0,n):
temp = a + b
b=a
a= temp
fibo()
Output::
Program.11. Python program to check if the number is an Armstrong number or not
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
Output::
Program. 12. Write a random number generator that generates random numbers between 1 and 6
(simulates a dice).
import random
min = 1
max = 6
roll_again = "y"
Output::
Program. 13. Create a CSV file by entering user-id and password, read and search the password
for given user id.
import csv
fileobj = csv.writer(obj)
while(True):
fileobj.writerow(record)
if x in "Nn":
break
elif x in "Yy":
continue
fileobj2 = csv.reader(obj2)
for i in fileobj2:
next(fileobj2)
if i[0] == given:
print(i[1])
break
Output::
Program. 14 Program to create binary file to store Rollno,Name and Marksand update
import pickle
student=[ ]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
student.append([roll,name,marks])
pickle.dump(student,f)
f.close()
f=open('student.dat','rb+')
student=[ ]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'
while ans.lower()=='y':
found=False
for s in student:
if s[0]==r:
s[2]=m
found=True
break
if not found:
f.close()
Output::
Program. 15. Write a python program to implement a stack using a list data-structure.
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=None
else:
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 is empty')
else:
top=len(stk)-1
print(stk[top],'<-top')
for i in range(top-1,-1,-1):
print(stk[i])
def main():
stk=[]
top=None
while True:
print('''stack operation
1.push
2.pop
3.peek
4.display
5.exit''')
if choice==1:
item=int(input('enter item:'))
push(stk,item)
elif choice==2:
item=pop(stk)
if item=="underflow":
print('stack is underflow')
else:
print('poped')
elif choice==3:
item=peek(stk)
if item=="underflow":
print('stack is underflow')
else:
display(stk)
elif choice==5:
break
else:
print('invalid')
exit()
main()
Output::
Program. 16. Write a python program to implement to deletes all the records from EMPLOYEE
whose AGE is more than 20 .
import mysql.connector
conn = mysql.connector.connect(
cursor = conn.cursor()
print(cursor.fetchall())
try:
cursor.execute(sql)
conn.commit()
except:
conn.rollback()
#Retrieving data
print(cursor.fetchall())
#Closing the connection
conn.close()
Output::
Program. 17. Create a student table and insert data. Implement the following SQL
i)- ALTER table to add new attributes / modify data type / drop attribute
v)- GROUP BY and find the min, max, sum, count and average
Solution:
#Describing table
mysql> desc student;
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| ROLLNO | int | NO | PRI | NULL | |
| NAME | char(10) | YES | | NULL | |
| TELUGU | char(10) | YES | | NULL | |
| HINDI | char(10) | YES | | NULL | |
| MATHS | char(10) | YES | | NULL | |
| computers | char(10) | YES | | NULL | |
+-----------+----------+------+-----+---------+-------+
#Droping a attribute
#Describing table
mysql> desc student;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| ROLLNO | int | NO | PRI | NULL | |
| NAME | char(10) | YES | | NULL | |
| TELUGU | char(10) | YES | | NULL | |
| HINDI | char(10) | YES | | NULL | |
| MATHS | char(10) | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
#ORDER BY BRANCH
#ACTUAL DATA
mysql> SELECT *FROM STUDENT;
+--------+--------+----------+--------+-------+-------+
| ROLLNO | BRANCH | NAME | TELUGU | HINDI | MATHS |
+--------+--------+----------+--------+-------+-------+
| 102 | MPC | student2 | 60 | 61 | 62 |
| 103 | BIPC | student3 | 70 | 71 | 72 |
| 104 | BIPC | student4 | 80 | 81 | 82 |
| 105 | BIPC | student5 | 90 | 91 | 92 |
| 106 | BIPC | student6 | 40 | 41 | 42 |
| 107 | MPC | student7 | 63 | 64 | 65 |
+--------+--------+----------+--------+-------+-------+