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:

  1. Read 6 marks from the user.

  2. Store them in a list.

  3. Apply Bubble Sort.

  4. Sort marks in descending order.

  5. 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

After sorting (Descending): 92 90 88 78 74 65


Flowchart (Block Diagram of Logic)

Flowchart Explanation
  • 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

  1. Start

  2. Create empty list

  3. Read 6 marks and store in list

  4. For i from 0 to 4

    • For j from 0 to (5 − i − 1)

      • If marks[j] < marks[j+1]

        • Swap the elements

  5. Display sorted marks

  6. 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

Enter 6 subject marks:
Enter mark: 78
Enter mark: 92
Enter mark: 65
Enter mark: 88
Enter mark: 74
Enter mark: 90

Marks from Highest to Lowest:
92.0
90.0
88.0
78.0
74.0
65.0

Important Concepts Used

  • List (1-Dimensional array)

  • Nested loops

  • Bubble Sort algorithm

  • Swapping technique

  • Comparison operators


Viva Voce Questions

  1. What is Bubble Sort?

  2. Why do we use nested loops?

  3. What is the time complexity of Bubble Sort?

  4. How many passes are required for 6 elements?

  5. Why is condition reversed for descending order?

  6. What happens if the list is already sorted?

  7. Can this be done using built-in sort() method?


Procedure to Execute the Program

  1. Open Python IDLE / VS Code / Google Colab

  2. Create a new file

  3. Type the program

  4. Save with .py extension

  5. Run the program

  6. Enter 6 subject marks


Google Colab – Online Execution

👉 Paste your Colab link here.

[https://colab.research.google.com/drive/1PEuHXIGQCpESt988YhF61nDEB6heITuy?usp=sharing]


Program Explanation



Assignment for Students
  • 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.



-:END:-



Comments

Popular posts from this blog