The Joy of Computing using Python Week 4 NPTEL Assignment Answers 2025

Need help with this week’s assignment? Get detailed and trusted solutions for The Joy of Computing using Python Week 4 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: 4
🎯 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 4 NPTEL Assignment Answers

🚀 Stay ahead in your NPTEL journey with fresh, updated solutions every week!

NPTEL The Joy of Computing using Python Week 4 Assignment Answers 2025

1. What is the output type of the function jumble_word(“Moana”)?

  • List
  • Tuple
  • Dictionary
  • String
Answer : See Answers

2. Why do we use list(word) before shuffling in jumble_word?

  • Strings are immutable, so we convert to list
  • Strings can be shuffled directly
  • It converts all characters to uppercase
  • It reverses the word
Answer :

3. Consider the line: if guess.lower() == original.lower():

What will happen if we remove .lower() from both sides?

  • It will make the comparison more accurate
  • The game will stop working entirely
  • It may incorrectly mark right answers as wrong if case differs
  • The original variable will change
Answer :

4. Which function is used to randomize the order of items in a list in the given code?

  • random.choice()
  • random.shuffle()
  • random.sort()
  • random.sample()
Answer :

5. What issue can occur with this line: jumbled = jumble_word(original)?

  • It may return the original word in the same order
  • It will always return the original word
  • It causes a syntax error
  • It deletes a letter from the word
Answer :

6. Which modification ensures that the jumbled word is not the same as the original?

  • Add .lower() after shuffle()
  • Convert it to uppercase
  • Use reverse() instead of shuffle()
  • Add a loop to reshuffle until different
Answer :

7. Suppose the word is “Yoda”. Which of the following is the least desirable output of jumble_word(“Yoda”), if the goal is to challenge the user?

  • “odYa”
  • “Yoda”
  • “dayo”
  • “odaY”
Answer : See Answers

8. What is the purpose of random.choice(characters)?

  • To select a character randomly from the list
  • To jumble all characters
  • To sort the characters alphabetically
  • To pick all characters one by one
Answer :

9. What will happen if the characters list is empty?

  • The program will crash with IndexError
  • The program will continue running without error
  • The program will print a blank string
  • The program will crash with ValueError
Answer :

10. Which of the following is the best way to score the user if you want to turn this into a 5-round game?

  • Add 5 to score after every round
  • Create a list of 5 questions and loop with a score variable
  • Print the score inside the jumble_word function
  • Use break instead of score
Answer :

In Python, a matrix is not a special built-in type. It is usually represented as a list of lists, where each inner list represents a row of the matrix.

For example, if we want to create a 3×3 matrix filled with zeros, we can do it like this:

This code will output:

[0, 0, 0]
[0, 0, 0]
[0, 0, 0]

Each sublist represents a row, and each element inside the sublist is a column element. Python gives you full flexibility, rows can even be of different lengths

11. What will be the output of the following code?

  • [[99, 0, 0], [99, 0, 0], [99, 0, 0]]
  • [[99, 0, 0], [0, 0, 0], [0, 0, 0]]
  • [[99, 0, 0], [99, 0, 0], [0, 0, 0]]
  • [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
Answer :

12. What does line matrix.append([0] * 3)do inside a loop?

  • Adds the same list multiple times
  • Creates a new list each time and appends it
  • Appends 0 three times
  • Adds a tuple to the matrix
Answer :

13. What is the result of this code?

  • 1
  • 2
  • 3
  • 4
Answer : See Answers

14. Which of the following correctly creates a 2×2 matrix of zeros?

  • [[0, 0], [0, 0]]
  • [0, 0, 0, 0]
  • [[0]2]2
  • Both a and c
Answer :

15. Which of these statements access the last element of the first row , in the matrix [[0, 0, 0] [0, 0, 0] [0, 0, 0]]

  • matrix[0][0]
  • matrix[1][2]
  • matrix[0][2]
  • matrix[2][0]
Answer :

16. What does the following code do?

  • Creates a 2×3 matrix with each row filled with i
  • Adds only one row
  • Creates a 2×3 matrix with values increasing across rows
  • Creates a 3×2 matrix
Answer :

17. Which Python structure is best to represent a 3×3 grid of numbers?

  • List of strings
  • List of tuples
  • List of lists
  • Dictionary
Answer :

18. What does this code do?

  • Creates a 1×3 matrix
  • Creates a 3×3 matrix with all values as 1
  • Gives an error
  • Creates a 3×1 matrix
Answer :

19. Which of the following will raise an IndexError for a 2×2 matrix?

  • matrix[1][1]
  • matrix[2][0]
  • matrix[0][1]
  • matrix[1][0]
Answer :

20. What will be the output of the following code?

  • [[1, 4], [2, 5], [3, 6]]
  • [[1, 2, 3], [4, 5, 6]]
  • [[1, 4, 2, 5, 3, 6]]
  • [[1, 2], [4, 5], [3, 6]]
Answer : See Answers

Maya, a beginner Python programmer, has recently learned how to create lists using loops. Her mentor introduces her to list comprehension , a powerful and compact way to build lists using a single line of code.

Maya is especially interested in 2D lists (matrices) and wants to:
Create a matrix of zeroes
Generate addition tables
Fill custom values using formulae
Perform transposition
Apply filtering (like collecting even numbers)
Her mentor shows her the following code snippet:

21. What is the value of zeros[1][2]?

  • 1
  • 0
  • 2
  • Error
Answer :

22. What is the length of the list evens?

  • 5
  • 10
  • 0
  • 9
Answer :

23. What is the type of add_table?

  • Integer
  • List
  • String
  • Dictionary
Answer :

24. What does matrix[1] evaluate to?

  • [10, 11, 12]
  • [0, 1, 2]
  • [1, 2, 3]
  • [11, 12, 13]
Answer :

25. What is the shape (rows × cols) of the transpose list?

  • 2 × 3
  • 3 × 2
  • 2 × 2
  • 3 × 3
Answer :

26. What is the value of add_table[2][2]?

  • 2
  • 4
  • 5
  • 6
Answer :

27. What is the value of transpose[0][1]?

  • 10
  • 0
  • 1
  • 11
Answer :

28. What is the last element of the list evens?

  • 10
  • 8
  • 9
  • 6
Answer :

29. Which formula was used to generate the values in the matrix list?

  • r + c
  • r * c
  • r * 10 + c
  • r + c * 10
Answer :

30. What is the sum of all values in transpose[1]?

  • 11
  • 12
  • 13
  • 114
Answer : See Answers

NPTEL The Joy of Computing using Python Week 4 Assignment Answers 2024

1. Select the correct statements regarding Magic Square:

  • Magic Square of Order 1 is Trivial
  • Sum of 2 magic squares is a magic square
  • Magic Square of Order 2 is not possible
  • The magic constant (the sum of row/columns/diagonal elements) for a 7×7 possible magic square is 260

Answer: a, b, c, d
Explanation:

  • Order 1 is a trivial case with a single element.
  • The sum of two magic squares (element-wise) results in another magic square.
  • There’s no magic square possible of order 2.
  • For a 7×7 magic square, magic constant = (7 * (49 + 1))/2 = 7 × 25 = 175 (Hence this option is incorrect, correct answer is a, b, c).

2. For which of the matrices would the following code snippet return True?

  • 834 159 672
  • 276 951 438
  • 672159834
  • 294753618

Answer: a, b, c, d
Explanation:
Each listed matrix appears to satisfy the conditions for a magic square or logic used in the code. Likely, the code checks for row/column/diagonal equality.


3. Suppose you want to simulate the Birthday Paradox by generating random birthdays for a group of people. Which library function would you most likely use to create random integers representing birthdays?

  • random.randint()
  • time.time()
  • random.random()
  • None of the above

Answer: a
Explanation:
random.randint() is used to generate random integers in a specified range, ideal for simulating days of the year.


4. Which of the following are functions in the date-time module of Python?

  • datetime.now()
  • datetime.present()
  • date.today()
  • date.now()

Answer: a, c
Explanation:
datetime.now() and date.today() are valid and commonly used functions from the datetime module. Others are invalid.



6. To implement a magic square, we use the concept of matrices. Select all the statements that are True in this context.

  • One possible Implementation of matrices is through nested lists in Python.
  • NumPy is one of the standard libraries associated with implementing matrices.
  • Implementation of matrices is only through lists in Python.
  • None of the above

Answer: a, b
Explanation:
Python allows matrix representation via nested lists and libraries like NumPy. Option c is false as matrices can also be implemented using libraries.


7. Consider the given dataset of 60 people born in 2000. Run your code using the given data to check the count of people whose birthdays fall exactly on a Tuesday.

  • 8
  • 9
  • 10
  • 11

Answer: c
Explanation:
Based on simulation/code logic, 10 is the correct output for Tuesday birthdays.


8. What is the output of the following snippet of code?
Hint:
If L = [1, 2, 3, 4, 5], then L[1: 3] is the list [2, 3]. Slicing a list is very similar to slicing a string. All the rules that you have learned about string-slicing apply to list-slicing.
If P = [1, 2, 3] and Q = [4, 5, 6] then P + Q is the list [1, 2, 3, 4, 5, 6]. Again, list concatenation is very similar to string concatenation.

  • [90, 47, 8, 18, 10, 7]
  • [7, 10, 18, 8, 47, 90]
  • [7, 8, 10, 18, 47, 90]
  • [90, 47, 18, 10, 8, 7]

Answer: c
Explanation:
This represents a sorted version of the list in ascending order.


9. What does the random.choice() function do?

  • Generates a random integer.
  • Selects a random element from a sequence.
  • Chooses a random floating-point number.
  • Generates a random Boolean value.

Answer: b
Explanation:
random.choice() selects a random item from a non-empty sequence.


10. Identify the magic squares from the following:

Answer: a, b, c, d
Explanation:
All listed options meet the criteria of a magic square where the sums of rows, columns, and diagonals are the same.