Need help with this week’s assignment? Get detailed and trusted solutions for The Joy of Computing using Python Week 6 NPTEL Assignment Answers. Our expert-curated answers help you solve your assignments faster while deepening your conceptual clarity.
✅ Subject: The Joy of Computing using Python
📅 Week: 6
🎯 Session: NPTEL 2025 July-October
🔗 Course Link: Click Here
🔍 Reliability: Verified and expert-reviewed answers
📌 Trusted By: 5000+ Students
For complete and in-depth solutions to all weekly assignments, check out 👉 NPTEL The Joy of Computing using Python Week 6 NPTEL Assignment Answers
🚀 Stay ahead in your NPTEL journey with fresh, updated solutions every week!
NPTEL The Joy of Computing using Python Week 6 Assignment Answers 2025
1. What data structure did Prof. Andrew use to store student marks where the key was the student’s name and the value was a list of marks?
- List of Lists
- List of Dictionaries
- Dictionary of Lists
- Dictionary of Dictionaries
Answer : See Answers
2. What will be the output of the following code?

- 85
- 92
- 89
- Error
Answer :
3. Fill in the blank to print Ravi’s English marks from the marks dictionary:

- 2
- 0
- 1
- 3
Answer :
4. Which of the following best describes when to use a list of dictionaries?
- When you want to access one student’s data quickly
- When the values are numbers only
- When you want to loop through each student’s complete record
- When you are storing a single subject’s marks
Answer :
5. What will be the output of the following code?

- Red
- Green
- Blue
- Ravi
Answer :
6. What type of data structure is students in the code used by Prof. Andrew?
- Dictionary of Lists
- Tuple of Dictionaries
- List of Dictionaries
- Dictionary of Tuples
Answer :
7. What will happen if Prof. Andrew writes print(students[“Ravi”][“house”])?
- It will print “Blue”
- It will cause an IndexError
- It will cause a TypeError
- It will cause a KeyError
Answer : See Answers
8. Prof. Andrew updates the students list by adding a new student record like this:

Now, what will be the output of the following code?

- 2
- 1
- 3
- 0
Answer :
9. Prof. Andrew wants to print the names of all students who belong to the “Red” house. Which of the following statements about how he should approach this task is correct?
- Loop over the marks dictionary and filter by house
- Loop over the students list and check the “house” key in each dictionary
- Use the key “Red” directly on the students list
- Use the values() method on the list to get all houses and then print names
Answer :
10. If Prof. Andrew wants to find out how many students scored above 90 in the first subject, what is the correct approach?
- Check if marks[name][1] > 90 for all students
- Loop through the students list and check “marks” key in each dictionary
- Loop through the marks dictionary and check if the first element of the list is greater than 90
- Sort the marks dictionary by name before checking scores
Answer :
Bubble Sort is a simple sorting algorithm that works by repeatedly comparing adjacent elements in a list and swapping them if they are in the wrong order.
Imagine arranging numbers from smallest to largest. In each pass through the list, the largest number “bubbles up” to its correct position at the end. This process continues until the entire list is sorted.

Compare 5 and 1 → swap
Compare 5 and 4 → swap
Compare 5 and 2 → swap
Compare 5 and 8 → no swap
After the first pass, 8 has reached its correct place. More passes sort the rest.
Why is it called Bubble Sort?
Because with each pass, the largest unsorted element “bubbles” to the top, like a bubble rising in water.
11. What will be the output after the first complete pass of bubble sort on the following list?

- [4, 7, 3, 2, 9]
- [9, 7, 4, 3, 2]
- [4, 3, 2, 7, 9]
- [9, 4, 7, 3, 2]
Answer :
12. How many total swaps will happen to fully sort the list below using bubble sort?

- 1
- 2
- 3
- 0
Answer :
13. Consider this bubble sort implementation:

What is the output?
- [1, 2, 4, 5, 8]
- [1, 4, 2, 5, 8]
- [1, 2, 4, 8, 5]
- Infinite loop
Answer :
14. What is the minimum number of passes required to sort this list using bubble sort?

- 0
- 1
- 4
- 5
Answer : See Answers
15. In which of the following cases will bubble sort perform the maximum number of comparisons?
- Already sorted list
- List sorted in reverse order
- List with all elements the same
- List with one element
Answer :
16. What will be the output of the following code?

- [5, 4, 3, 2, 1]
- [4, 5, 3, 2, 1]
- [5, 3, 4, 2, 1]
- [2, 3, 1, 5, 4]
Answer :
17. Which of the following would improve bubble sort’s performance on already sorted lists?
- Increasing the number of passes
- Using a flag to break early if no swaps occur
- Always sorting in reverse
- Swapping even if elements are equal
Answer :
18. You have a list:
arr = [10, 20, 30, 40, 25]
After how many passes will 40 reach its correct position using bubble sort?
- 1
- 2
- 3
- 4
Answer :
19. What will be the final output of the following variant of bubble sort?

- [1, 2, 3, 5, 6]
- [2, 1, 3, 5, 6]
- [6, 5, 3, 2, 1]
- [1, 3, 2, 5, 6]
Answer :
20. 1 point
Prof. Andrew wanted to make his Bubble Sort more efficient by adding a swapped flag to break early if no swaps happen during a pass.
Here’s the code:

What will be the output?
- 0
- 1
- 4
- 5
Answer : See Answers
It was the day before the annual sports day at college. Prof. Andrew was helping students line up for the march past, but he had a problem. The students were standing in random order based on their heights, and he wanted them arranged from shortest to tallest.
Instead of asking them all to sort themselves, Prof. Andrew used a simple strategy — something computers also use. It’s called Selection Sort.
What is Selection Sort?
Selection Sort is a sorting algorithm where we select the smallest (or largest) item from the unsorted part of the list and put it at the correct position in the sorted part — step by step.
It’s like arranging students in height order one at a time.
Let’s say these are the student heights:
heights = [165, 150, 172, 160]
Step 1:
Look through the entire list to find the shortest student (150).
Swap it with the first student in line.
Now the line looks like: [150, 165, 172, 160]
Step 2:
From the remaining (unsorted) list [165, 172, 160], find the shortest → 160.
Swap it with the second position.
Now: [150, 160, 172, 165]
Step 3:
From [172, 165], find the smallest → 165.
Swap with third position → [150, 160, 165, 172]
Now the list is fully sorted!
21. Which of the following best describes the core idea of selection sort?
- Swap every adjacent pair that is out of order.
- Select the largest element and place it at the beginning.
- Select the smallest element and place it at the correct position in each pass.
- Randomly shuffle until the list is sorted.
Answer :
22. How many swaps are made in total when sorting [4, 3, 2, 1] using selection sort?
- 6
- 3
- 4
- 2
Answer :
23. What will be the output of the following code?

- [1, 2, 4, 5]
- [5, 4, 2, 1]
- [1, 4, 2, 5]
- [1, 2, 5, 4]
Answer :
24. Which one of the following is true about the number of comparisons in selection sort?
- It depends on whether the list is sorted or not
- It varies based on data size and value
- It always performs the same number of comparisons
- It stops early if no swap is needed
Answer :
25. What happens if all elements in the list are already equal?
- Selection sort performs no swaps or comparisons
- Selection sort skips sorting
- It performs comparisons but makes zero swaps
- It performs swaps with random elements
Answer :
26. What is the output after the second pass of selection sort on this list?
arr = [9, 3, 7, 1, 5]
- [3, 1, 7, 9, 5]
- [1, 3, 7, 5, 9]
- [1, 3, 7, 9, 5]
- [1, 3, 5, 7, 9]
Answer :
27.

What is wrong with this code?
- Nothing, it works fine
- It doesn’t place the smallest element correctly
- It overwrites values and loses elements
- It misses the last element in sorting
Answer :
28.

What’s the problem here?
- Inner loop misses comparing the last element
- It swaps elements incorrectly
- Outer loop runs too many times
- List becomes reversed
Answer :
29.

What is the mistake here?
- The code doesn’t swap anything
- The wrong element is selected as the minimum
- min_idx is not reset correctly
- The loop condition is wrong
Answer :
30.

This code runs correctly, but what small optimization could improve performance?
- Remove the outer loop
- Break if the list is sorted
- Check if min_idx != i before swapping
- Change selection sort to bubble sort
Answer : See Answers
NPTEL The Joy of Computing using Python Week 6 Assignment Answers 2024
1. What is the output of the following code?
a. 14930352
b. 75025
c. 610
d. None of the above
✅ Answer :- b
Explanation: The code likely returns the 24th Fibonacci number, which is 75025.
2. Which method in Python is used to convert lowercase letters in a string to uppercase?
a. upper()
b. capitalize()
c. casefold()
d. swapcase()
✅ Answer :- a
Explanation: upper() converts all lowercase letters in a string to uppercase.
3. What is the primary objective of the Min-Max algorithm?
a. Maximizing the player’s score
b. Minimizing the opponent’s score
c. Minimizing the maximum possible loss
d. Maximizing the number of moves
✅ Answer :- c
Explanation: The Min-Max algorithm minimizes the maximum possible loss, ensuring optimal decision-making under adversarial conditions.
4. What would be the output of the following code?
a. 123
b. ValueError
c. SyntaxError
d. NameError
✅ Answer :- b
Explanation: The code likely tries to convert an invalid string to a number, raising a ValueError.
5. What term is used in programming languages when a function calls itself?
a. Self-referencing
b. Iteration
c. Recursion
d. Circular referencing
✅ Answer :- c
Explanation: Recursion refers to a function that calls itself in its definition.
6. If L is a non-empty list of positive integers, which of the following is correct about the recursive function func(L)?
a. It returns the total number of odd elements in the list L
b. It returns the total number of even elements in the list L
c. It returns the sum of the even elements in the list L
d. It returns the sum of the odd elements in the list L
✅ Answer :- b
Explanation: Based on the logic, the function likely counts even numbers in the list recursively.
7. If L is a non-empty list of positive integers, which of the following is correct about the recursive function func(L)?
a. It returns the total number of odd elements in the list L
b. It returns the total number of even elements in the list L
c. It returns the sum of the even elements in the list L
d. It returns the sum of the odd elements in the list L
✅ Answer :- d
Explanation: This version of the function appears to sum only the odd numbers recursively.
8. What purpose does a base case serve in recursive functions?
a. To make the function run faster
b. To eliminate the need for additional functions
c. To prevent infinite recursion and ensure termination
d. To enable the function to handle complex calculations
✅ Answer :- c
Explanation: A base case is essential in recursion to stop the function from calling itself indefinitely.
Q. 9. 10.
Consider the following function f that accepts an integer as argument n.

9. What is the value returned by f(10000)?
✅ Answer :- 7
Explanation: Without code, it appears the function recursively divides or reduces n and counts steps—7 for 10000.
10. What is the value returned by f(-8)?
✅ Answer :- 8
Explanation: The function likely handles negative input by counting the digits or operations—resulting in 5.

