0% found this document useful (0 votes)
3 views

CS 1

Class 12 computer science program python

Uploaded by

sssultt05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CS 1

Class 12 computer science program python

Uploaded by

sssultt05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Question-Design a python program to implement

following stack operation using list:


(i) Push Operation
(ii) Pop Operation
(iii) Peek Operation
(iv) Display Stack
(v) Exit
SOURCE CODE:-
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:
Python 3.HL2 (tc1gs/v3.10.2:a58ebcc, Jan 17 2022, l":l::12:15), [MSC v.1929 6":l: bit (
AMD6":l:),] on win32
Type "help", "copyi:ight", "ci:edits" oi: "license()" foi: moi:e infoi:ro,c1tion.
>>>
= RESTART: C:/Usei:s/DE L/AppData/Local/Pi:ogi:ams/Python/Python310/code/l.py
STACK OPERATIONS:
l.Push
2.Pop
3.Peek
":l:.Display Stack
5.Exit
Enter your choice (1-5):l
Enter item:":l:O
STACK OPERATIONS:
l.Push
2.Pop
3.Peek
":l:.Display Stack
5.E.xit
Enter your choice (1-
5):2 Popped item is:
None STACK OPERATIONS:
l.Push
2.Pop
3.Peek
":l:.Display Stack
5.Exit
Enter your choice (1-5):3
Underflow! Stack is Empty
STACK OPERATIONS:
l.Push
2.Pop
3.Peek
":l:.Display Stack
5.E.xit
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 1:-

Output 2:-
Question 1:- Create a student table with the student id, name,
city and marks as attributes where the student id is the primary
key.
QUERY:-
mysql-> create table students
-> (sid char(5),
-> name char(15),
-> city char(20),
-> marks decimal(5,2));
Question 2:- Write a query to insert the details of a new
student(„S5‟,‟KUINKA‟,‟MORENA‟,53.6) in the above table.
QUERY:-
mysql> INSERT INTO student
-> values('s5','kuinka','morena',53.6);
OUTPUT 3:-

OUTPUT 4:-
Question 3:- Write a query to delete the details of a student in
the above table.
QUERY:-
mysql> delete from students
-> where sid='s2';
Question 4:- Write a query to display the details of the
students with marks more than 80.
QUERY:-
mysql> select*from students
-> where marks>80;
OUTPUT 5:-

OUTPUT 6:-
Question 5:- Write a query to find the min, max, sum, and
average of the marks in a students table.
QUERY:-
mysql> select min(marks),max(marks),sum(marks),avg(marks)
from students;
Question 6:- Write a query to find the total number of students
from each city in the table Customer (SID, Name, City) using
group by.
QUERY:-
mysql> select city,count(*) from students group by city;
OUTPUT 7:-

OUTPUT 8:-
Question 7:- Write a query to display the (student ID
marks) table in descending order of the marks.
QUERY:-
mysql> select sid, marks from students order by
marks desc;
Question 8:- Write a query to display the number of students
with same class.
QUERY:-
mysql> select class,count(*) from students group by class;
OUTPUT 9:

OUTPUT 10:-
Question 9:- Write a query to display the class where the
number of student is less than 3 from students table.
QUERY:-
mysql> select class,count(*) from students group by class
having count(*) >3;
Question 10:- Write a query to display the Sum, Average,
Highest and Lowest marks of the students grouped by class.
QUERY:-
mysql>selectClass,sum(Marks),avg(Marks) ,max(Marks),
min(Marks) from students Group by class;
OUTPUT 11:-

OUTPUT 12:-

OUTPUT 13:-
Question 11:- Write a query to display the number of students
city wise.
QUERY:-
mysql> select city,count(*) from students group by city;
Question 12:- Write a query to display names “MR. OBAMA”
and “MS. Gandhi‟ into lower case.
QUERY:-
mysql> select lcase('MR. OBAMA'),Lcase('MS. Gandhi');
Question 13:- Write a query to display 4 characters extracted
from 3rd left character onwards from string “ABCDEFG”.
QUERY:-
mysql> select substr('ABCDEFG',3);
OUTPUT 14:-

OUTPUT 15:-
Question 14:- Write a query to count the number of characters
are there in string “CANDIDATE”.
QUERY:-
mysql> select length("CANDIDATE");
Question 15:- Write a query to delete the details of a student
(”KUINKA”) from the students table.
QUERY:-
mysql> delete from students where name="kuinka";

You might also like