Program5
5. Develop a program to read 6 subject marks from the keyboard for a student. Generate a report that displays the marks from the highest to the lowest score attained by the student. [Read the marks into a 1-Dimesional array and sort using the Bubble Sort technique].
Objective of the Program
To understand array (list) usage
To implement Bubble Sort manually
To arrange data in descending order
To understand nested loops
Logical Construction (Think Before You Code)
We must:
Read 6 marks from the user.
Store them in a list.
Apply Bubble Sort.
Sort marks in descending order.
Display sorted report.
What is Bubble Sort?
Bubble Sort works by:
Comparing adjacent elements
Swapping them if they are in wrong order
Repeating the process until the list is sorted
Example
Input Marks: 78 92 65 88 74 90
Flowchart (Block Diagram of Logic)
Start
Read 6 marks
Store in list
Apply nested loops
Compare adjacent elements
Swap if left < right (for descending order)
Repeat passes
Display sorted list
Stop
Algorithm
Start
Create empty list
Read 6 marks and store in list
For i from 0 to 4
For j from 0 to (5 − i − 1)
If marks[j] < marks[j+1]
Swap the elements
Display sorted marks
Stop
Python Program
⚠ Students must complete the missing parts.
# Program to sort 6 subject marks using Bubble Sort
marks = []
print("Enter 6 subject marks:")
for i in range(6):
value = float(input("Enter mark: "))
marks.append(__________)
# Bubble Sort (Descending Order)
for i in range(6):
for j in range(0, 6 - i - 1):
if marks[j] < ____________:
temp = marks[j]
marks[j] = ____________
marks[j + 1] = temp
print("Marks from Highest to Lowest:")
for mark in marks:
print(mark)
Probable Output
Important Concepts Used
List (1-Dimensional array)
Nested loops
Bubble Sort algorithm
Swapping technique
Comparison operators
Viva Voce Questions
What is Bubble Sort?
Why do we use nested loops?
What is the time complexity of Bubble Sort?
How many passes are required for 6 elements?
Why is condition reversed for descending order?
What happens if the list is already sorted?
Can this be done using built-in sort() method?
Procedure to Execute the Program
Open Python IDLE / VS Code / Google Colab
Create a new file
Type the program
Save with
.pyextensionRun the program
Enter 6 subject marks
Google Colab – Online Execution
👉 Paste your Colab link here.
[https://colab.research.google.com/drive/1PEuHXIGQCpESt988YhF61nDEB6heITuy?usp=sharing]
Program Explanation
Modify program to sort in ascending order
Display highest and lowest marks separately
Count number of swaps
Modify program for N subjects
Lab Record Instructions
Right Side of the Record
1. Problem Statement
2. Python Program
Write the following neatly on the right-hand side page:
Left Side of the Record
Write the following neatly on the left-hand side page:
3. Flowchart
4. Algorithm
5. Output
⚠️ Students must write ALL possible outputs.

Comments
Post a Comment