a python code to sort a list in ascending order using bubble sort
def bubble_sort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already sorted, so we don't need to check them
for j in range(0, n - i - 1):
# Swap if the element found is greater than the next element
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
# Example Usage:
my_list = [64, 25, 12, 22, 11]
print("Original List:", my_list)
bubble_sort(my_list)
print("Sorted List:", my_list)
output:
Original List: [64, 25, 12, 22, 11]
Sorted List: [11, 12, 22, 25, 64]
a python program to open a file “[Link]” in write mode and write the following lines. open the same file in read
mode to display the contents.
“COUNCIL OF HIGHER SECONDARY EDUCATION MANIPUR”
# Open the file in write mode and write the line
with open("[Link]", "w") as file:
[Link]("COUNCIL OF HIGHER SECONDARY EDUCATION MANIPUR")
# Open the file in read mode and display its contents
with open("[Link]", "r") as file:
contents = [Link]()
print("Contents of '[Link]':")
print(contents)
OUTPUT:
Contents of '[Link]':
COUNCIL OF HIGHER SECONDARY EDUCATION MANIPUR
Consider the table STUDENT and write the SQL commands for the following questions based on it :
[Link] NAME STREAM STIPEND AGE SEX
1 RAKESH COMMERCE 2000 20 M
2 BEENA MEDICAL 2500 22 F
3 AMITA HUMANITIES 2200 21 F
4 AMARJIT SCIENCE 2400 23 M
5 KIRAN MEDICAL 2100 24 M
6 DIANA MEDICAL 2800 22 F
7 LOREN SCIENCE 2400 21 M
8 ROGER COMMERCE 2600 25 M
9 DENIAL HUMANITIES 2500 26 M
10 HENERITA MEDICAL 3000 25 F
(a) To display all the information of male student
(b) Display NAME,STREAM and STIPEND of female students.
(c) List all the students whose name starts with “D”.
(d) List the names of the students having the stream commerce and science.
(e) Display the total stipend of male student.
(f) List all the students in descending order of their stipend.
(g) Count the number of students in MEDICAL stream.
(h) To insert a new row in the table with the values.
11,”JOHN”,”SCIENCE”,2700,24,”M”
(a)To display all the information of male students:
SELECT * FROM STUDENT WHERE SEX = 'M';
Output:
SL_no | NAME | STREAM | STIPEND | AGE | SEX
------+-----------+-------------+---------+-----+-----
1 | RAKESH | COMMERCE | 2000 | 20 | M
4 | AMARJIT | SCIENCE | 2400 | 23 | M
5 | KIRAN | MEDICAL | 2100 | 24 | M
7 | LOREN | SCIENCE | 2400 | 21 | M
8 | ROGER | COMMERCE | 2600 | 25 | M
9 | DENIAL | HUMANITIES | 2500 | 26 | M
11 | JOHN | SCIENCE | 2700 | 24 | M
(b) Display NAME, STREAM, and STIPEND of female students:
SELECT NAME, STREAM, STIPEND FROM STUDENT WHERE SEX = 'F';
Output: NAME | STREAM | STIPEND
-----------+-------------+---------
BEENA | MEDICAL | 2500
AMITA | HUMANITIES | 2200
DIANA | MEDICAL | 2800
HENERITA | MEDICAL | 3000
(c) List all the students whose name starts with “D”:
SELECT * FROM STUDENT WHERE NAME LIKE 'D%';
Output: SL_no | NAME | STREAM | STIPEND | AGE | SEX
------+-----------+-------------+---------+-----+-----
6 | DIANA | MEDICAL | 2800 | 22 | F
9 | DENIAL | HUMANITIES | 2500 | 26 | M
(d) List the names of the students having the stream commerce and
science:
SELECT NAME FROM STUDENT WHERE STREAM IN ('COMMERCE', 'SCIENCE');
Output: NAME
-----
RAKESH
AMARJIT
LOREN
ROGER
JOHN
(e)Display the total stipend of male students:
SELECT SUM(STIPEND) AS TotalStipend FROM STUDENT WHERE SEX = 'M';
output: TotalStipend
-------------
14700
(f) List all the students in descending order of their stipend:
SELECT * FROM STUDENT ORDER BY STIPEND DESC;
Output: SL_no | NAME | STREAM | STIPEND | AGE | SEX
------+-----------+-------------+---------+-----+-----
10 | HENERITA | MEDICAL | 3000 | 25 | F
6 | DIANA | MEDICAL | 2800 | 22 | F
8 | ROGER | COMMERCE | 2600 | 25 | M
11 | JOHN | SCIENCE | 2700 | 24 | M
2 | BEENA | MEDICAL | 2500 | 22 | F
9 | DENIAL | HUMANITIES | 2500 | 26 | M
4 | AMARJIT | SCIENCE | 2400 | 23 | M
7 | LOREN | SCIENCE | 2400 | 21 | M
3 | AMITA | HUMANITIES | 2200 | 21 | F
5 | KIRAN | MEDICAL | 2100 | 24 | M
1 | RAKESH | COMMERCE | 2000 | 20 | M
(g) Count the number of students in MEDICAL stream:
SELECT COUNT(*) AS MedicalStudentsCount FROM STUDENT WHERE STREAM = 'MEDICAL';
Output:
MedicalStudentsCount
---------------------
4
(h) To insert a new row in the table with the values. 11, "JOHN", "SCIENCE",
2700, 24, "M":
INSERT INTO STUDENT (SL_no, NAME, STREAM, STIPEND, AGE, SEX) VALUES (11, 'JOHN', 'SCIENCE', 2700, 24,
'M');