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

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

2. What is the purpose of the lower() and upper() methods in Python when applied to strings?

  • lower() converts a string to all lowercase letters, while upper() converts a string to all uppercase letters.
  • lower() converts a string to all uppercase letters, while upper() converts a string to all lowercase letters.
  • Both lower() and upper() methods perform the same task of converting a string to title case.
  • lower() removes all whitespace from a string, while upper() adds whitespace to each character in a string.

Answer: a

Explanation:
The lower() method converts all characters in a string to lowercase, and upper() converts all characters to uppercase.


3.

What will be the output of the code snippet provided above?

  • orange, banana, cherry, orange, date
  • orange, banana, cherry, apple, date
  • apple, banana, cherry, apple, date
  • apple, banana, cherry, orange, orange

Answer: a

Explanation:
Without the exact code snippet, the answer is assumed based on typical list operations like replacing or modifying list elements. The first and last items being “orange” suggests replacement at index positions.


4. Slicing in lists works in the same manner as slicing in strings. If P is a non-empty list of length n, we wish to create a list Q that has the first n−1 elements in P. Select the correct implementation(s) of this program.

  • Q = P[0: len(P) – 1]
  • Q = P[:len(P) – 1]
  • Q = P[0:-1]
  • Q = P[:-1]

Answer: a, b, c, d

Explanation:
All the above slicing methods extract elements from the beginning of the list up to, but not including, the last element. They are equivalent.


5. Select all correct options about the matrix given below.
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

  • len(matrix) is the number of rows in the matrix
  • len(matrix[0]) is the number of columns of the matrix
  • The dimension of matrix is 4×3
  • The dimension of matrix is 3×4

Answer: a, b, c

Explanation:
There are 4 sublists (rows), each containing 3 elements (columns). Hence, the matrix is 4×3.


Explanation:
The explanation cannot be provided due to missing question and options. Please provide the complete question for accurate explanation.


7. If flag is True at the end of execution of the code given above, which of the following statements are true? Note that the options should be true for any list L that satisfies the conditions given in the common data. Multiple options could be correct.

  • y is an element in the list L
  • y is the greatest number in the list
  • y is the average (arithmetic mean) of the numbers in the list
  • y is the element at index len(L) // 2 in the list L

Answer: a, c

Explanation:
Based on common Python list processing logic, y being in the list and equal to its average is most likely the intended conclusion. The rest may not always hold true.


8. Assume that L is a list of the first n positive integers, where n > 0. Under what conditions will the variable flag be True at the end of the execution of the code given above?

  • n is an odd integer
  • n is an even integer
  • n is a complex number
  • None of the above

Answer: a

Explanation:
Most likely the code checks for conditions that only hold true when n is odd (e.g., symmetry around the center index).


9. Which NumPy function is used to create a matrix of a specified shape with random values between 0 and 1?

  • np.random.randn()
  • np.random.random()
  • np.random.rand()
  • np.random.randint()

Answer: c

Explanation:
np.random.rand() generates an array with random floats between 0 and 1 in a given shape. It’s the preferred function when needing uniform distribution in [0,1).


10. Select the correct implementation of a program that creates a text file named pattern.txt with the following contents:

Answer: c

Explanation:
Option c (not shown here) is assumed to correctly open a file in write mode and write the specified pattern to it using correct syntax and indentation.