Professional Documents
Culture Documents
CS Practical File For Term-2
CS Practical File For Term-2
Class-XII
Subject: COMPUTER SCIENCE (083)
Ans:
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("Empty Stack")
else:
top=len(stk)-1
print(stk[top],"<--top")
for a in range(top-1,-1,-1):
print(stk[a])
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("Top most 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 item:40
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):4
40 <--top
25
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):1
Enter item:30
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):3
Top most item is: 30
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):2
Popped item is: 30
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):4
40 <--top
25
STACK OPERATIONS:
1.Push
2.Pop
3.Peek
4.Display Stack
5.Exit
Enter your choice (1-5):5
>>>
PART-B : Database Management(MySQL) :
Table: Student
Sid Name City Marks
S5 KUINKA MORENA 53.6
S1 MONIKA GWALIOR 83.5
S2 RANJEET RANCHI 78.6
S3 JOHN ENGLAND 82.4
S4 ANSHIKA PATNA 68.2
S6 HARISH SHILONG 92.7
1. Create a student table with the student id, name, city and marks as attributes
where the student id is the primary key.
Mysql> create table student(sid char(5) not null primary key, name
char(15),city char(16),marks decimal(5,2));
Query OK, 0 rows affected (0.28 sec)
4. Write a query to display the details of the students with marks more than 80
5. Write a query to find the min, max, sum, and average of the marks in a
student table.
6. Write a query to find the total number of students from each city in the table
Customer (SID, Name, City) using group by.
7. Write a query to display the (student ID, marks) table in descending order of
the marks.
9. Write a query to display the class where the number of student is less than 3
from student table.
10. Write a query to display the Sum, Average, Highest and Lowest marks of
the students grouped by class.
12. Write a query to display names „MR. OBAMA and „MS. Gandhi‟ into
lower case.
14. Write a query to count the number of characters are there in string
“CANDIDATE”.
***********************