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.