NPTEL The Joy of Computing using Python Week 8 Assignment Answers 2024
1. Which of the following statements about tuples in Python is correct?
a. Tuples are mutable, allowing modification of individual elements after creation.
b. Tuples are enclosed in square brackets [ ], similar to lists.
c. Tuples are immutable, meaning their elements cannot be changed after creation
d. Tuples can only contain elements of the same data type.
✅ Answer :- c
Explanation: Tuples are immutable, meaning once created, their elements cannot be altered.
2. Which of the following statements are true about Tuples?
a. A tuple can hold mutable objects.
b. Tuples can be nested.
c. A list can be converted into a tuple and vice versa.
d. A tuple can hold a non-homogeneous sequence of items, viz. a_tuple = (1, 'cool', True)
✅ Answer :- a, b, c, d
Explanation: Tuples are versatile and can contain any object types, be nested, and be converted from/to lists.
3. Which of the following best describes the role of matplotlib.pyplot in Python’s matplotlib library for data visualization?
a. It is used for creating figures, plots, adding labels, and other visual elements to create visualizations.
b. It primarily handles numerical computations and statistical analyses for data visualization.
c. It manages data structures and handles data manipulation before visualization.
d. It is responsible for creating interactive visualizations and animations.
✅ Answer :- a
Explanation: matplotlib.pyplot
is the primary plotting interface in the matplotlib library.
4. Given a piece of text, which code determines how many words are there in the text (excluding special characters)?





✅ Answer :- d
Explanation: The correct code splits the string on spaces and ignores special characters, returning an accurate word count.
5. How does the given code check if two strings are anagrams? [MSQ]
a. Compares the lengths of the two input strings. If they are equal, it proceeds to check the character counts in each string.
b. Using a loop to count the occurrence of character present at even places in both strings.
c. Iterates through each character in word1 and compares the count of that character in both word1 and word2. If the counts match for all characters, the strings are considered anagrams
d. Compares the lengths of the two input strings. If they are not equal, it proceeds to check the character counts in each string
✅ Answer :- a, c
Explanation: The anagram-checking code compares string lengths and validates character frequencies.
6. If two strings are anagrams, what would be the output of the above code? [MSQ]
a. The output in case of anagram(“listen”, “silent”) is True
b. A Boolean Value
c. The output in case of anagram(“hello”, “world”) is True
d. The output in case of anagram(“race”, “care”) is True
✅ Answer :- a, b, d
Explanation: Anagram detection returns True
for matching words and a boolean value overall.
7. Consider the tuple colors = ('red', 'green', 'blue')
. What is the result of colors + ('purple')
?
a. (‘red’, ‘green’, ‘blue’, ‘purple’)
b. TypeError: can only concatenate tuple (not “str”) to tuple (‘red’, ‘green’, ‘blue’)
c. (‘red’, ‘green’, ‘blue’, ‘red’, ‘green’, ‘blue’, ‘purple’)
d. (‘red’, ‘green’, ‘blue’)
✅ Answer :- b
Explanation: 'purple'
is a string, not a tuple. To concatenate correctly, use ('purple',)
.
8. Which statement accurately describes the use of VADER and DataFrames in sentiment analysis?
a. VADER is a machine learning-based tool used with DataFrames to analyze sentiment in images.
b. VADER is a lexicon and rule-based sentiment analysis tool often used with Pandas DataFrames to assess sentiment in text data.
c. DataFrames are used to visualize sentiment analysis results, while VADER is a Python visualization library.
d. VADER and DataFrames are used in data preprocessing, not specifically in sentiment analysis tasks.
✅ Answer :- b
Explanation: VADER is a sentiment analyzer used with text data stored and processed in Pandas DataFrames.
9. Which of the following is correct?
Statement 1: The method used for flipping the image in the PIL library is transpose(parameter)
Statement 2: CLAHE (Contrast Limited Adaptive Histogram Equalization) is favoured over AHE for its advantage in handling noise
a. Only one of the above two statements is correct
b. Both statements are correct
c. Both statements are incorrect
d. Insufficient information to determine the correctness of both statements
✅ Answer :- c
Explanation: Statement 1 is partially correct but vague; Statement 2 is factually wrong—CLAHE is used to handle noise, so both statements are not fully correct.
10. Consider the following snippet of code.

Which of the following snippets of code will throw an error?



✅ Answer :- b, c
Explanation: Snippets b and c likely contain incorrect tuple syntax or indexing logic that results in runtime errors.