The Joy of Computing Using Python NPTEL Week 8 Answers

Are you looking for The Joy of Computing Using Python NPTEL Week 8 Answers? You’ve come to the right place! Access the latest and most accurate solutions for your Assignment 8 in The Joy of Computing Using Python course

Course Link: Click Here


The Joy of Computing Using Python NPTEL Week 8 Answers (July-Dec 2024)
The Joy of Computing Using Python NPTEL Week 8 Answers

The Joy of Computing Using Python NPTEL Week 8 Answers (July-Dec 2024)


  1. Which of the following is a valid way to create a tuple in Python?
    A) t = [1, 2, 3]
    B) t = (1, 2, 3)
    C) t = {1, 2, 3}
    D) t = 1, 2, 3

Answer: B) t = (1, 2, 3)
D) t = 1, 2, 3



  1. Which of the following operations is valid on a tuple?
    A) t[1] = 4
    B) t.append(4)
    C) t = t + (4,)
    D) del t[1]

Answer: C) t = t + (4,)


  1. What will the following code output?
    t = [1, 2, 3]
    print(type((t,t)))
    A) <class ’list’>
    B) <class ’set’>
    C) <class ’tuple’>
    D) Error

Answer: C) <class ’tuple’>


  1. What is the primary purpose of the matplotlib.pyplot module in Python?
    A) To perform matrix operations.
    B) To handle file I/O operations.
    C) To generate and customize visualizations like plots and graphs.
    D) To manipulate and process images.

Answer: C) To generate and customize visualizations like plots and graphs.


  1. Which of the following statements is true about anagrams?
    A) Two strings of different lengths can be anagrams.
    B) Two strings are anagrams if they contain the same characters in the same order.
    C) Two strings are anagrams if they contain the same characters in different orders.

Answer: C) Two strings are anagrams if they contain the same characters in different orders.


  1. Every character, whether an alphabet, digit, or special character, has an ASCII value. Which of the following methods is used to find the ASCII value?
    A) ASCII(’a’)
    B) ord(’a’)
    C) int(’a’)
    D) ASC val(’a’)

Answer: B) ord(’a’)


  1. Which of the following libraries is commonly used to determine the intensity of emotions in sentiment analysis?
    A) VADER
    B) Numpy
    C) Pandas
    D) SciPy

Answer: A) VADER


  1. Which of the following Python code snippets correctly checks if two strings are anagrams?
    A) def are_anagrams(str1, str2): return sorted(str1) == sorted(str2)
    B) def are_anagrams(str1, str2): return set(str1) == set(str2)
    C) def are_anagrams(str1, str2): return str1 == str2[::-1]
    D) def are_anagrams(str1, str2): return len(str1) == len(str2)

Answer: A) def are_anagrams(str1, str2): return sorted(str1) == sorted(str2)


  1. Why is gambling generally a bad decision?
    A) Because you will lose more money than you win over time.
    B) Because the probability of winning is always 0.
    C) Because you will always win.
    D) Because the amount of money you can win is always greater than the amount you lost over time.

Answer: A) Because you will lose more money than you win over time.


  1. True or False: A significant amount of information can be extracted from an image by applying the appropriate image enhancement techniques.
    A) True
    B) False

Answer: A) True


These are The Joy of Computing Using Python NPTEL Week 8 Answers

All Weeks of The Joy of Computing Using Python: Click here

For answers to additional Nptel courses, please refer to this link: NPTEL Assignment Answers


The Joy of Computing Using Python NPTEL Week 8 Answers (JAN-APR 2024)

Course Name:  The Joy of Computing using Python

Course Link: Click Here

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Q1. Which of the following statements about tuples in Python is correct?
Tuples are mutable, allowing modification of individual elements after creation.
Tuples are enclosed in square brackets [ ], similar to lists.
Tuples are immutable, meaning their elements cannot be changed after creation
Tuples can only contain elements of the same data type.

Answer: Tuples are immutable, meaning their elements cannot be changed after creation


Q2. Tuples share a close resemblance to lists. They can be indexed and sliced just like lists. The main point of difference between lists and tuples is that tuples cannot be updated in-place. Elements in a tuple cannot be deleted. Which of the following statements are true about Tuples:
A tuple can hold mutable objects.
Tuples can be nested.
A list can be converted into a tuple and vice versa.
A tuple can hold a non-homogeneous sequence of items, viz. a_tuple = (1, ‘cool’, True).

Answer: a, b, c, d

See also  The Joy of Computing Using Python NPTEL Assignment 2 Answers

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Q3. Which of the following best describes the role of matplotlib.pyplot in Python’s matplotlib library for data visualization?
It is used for creating figures, plots, adding labels, and other visual elements to create visualizations.
It primarily handles numerical computations and statistical analyses for data visualization.
It manages data structures and handles data manipulation before visualization.
It is responsible for creating interactive visualizations and animations.

Answer: It is used for creating figures, plots, adding labels, and other visual elements to create visualizations.


Q4. The following paragraph is an excerpt from a talk given by Guido:

In reality, programming languages are how programmers express and communicate ideas — and the audience for those ideas is other programmers, not computers. The reason: the computer can take care of itself, but programmers are always working with other programmers, and poorly communicated ideas can cause expensive flops. In fact, ideas expressed in a programming language also often reach the end users of the program — people who will never read or even know about the program, but who nevertheless are affected by it.
Text processing plays an important role in analysing text data. Given a piece of text, which of the following piece of code determines if how many words are there in the text?

a)
b)
c)
d)

Answer: c)


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Q5. How does the given code check if two strings are anagrams?[MSQ]
Compares the lengths of the two input strings. If they are equal, it proceeds to check the character counts in each string.
Using a loop to count the occurrence of character present at even places in both strings.
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
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


Q6. If two strings are anagrams, what would be the output of the above code? [MSQ]
The output in case of anagram(“listen”, “silent”) is True
A Boolean Value
The output in case of anagram(“”hello”, “world”) is True
The output in case of anagram(“race”, “care”) is True

Answer: a, b, d


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Q7. Consider the tuple colors = (‘red’, ‘green’, ‘blue’). What is the result of colors + (‘purple’)?
(‘red’, ‘green’, ‘blue’, ‘purple’)
TypeError: can only concatenate tuple (not “str”) to tuple (‘red’, ‘green’, ‘blue’)
(‘red’, ‘green’, ‘blue’, ‘red’, ‘green’, ‘blue’, ‘purple’)
(‘red’, ‘green’, ‘blue’)

Answer: TypeError: can only concatenate tuple (not “str”) to tuple (‘red’, ‘green’, ‘blue’)


Q8. Which statement accurately describes the use of VADER and DataFrames in sentiment analysis?
VADER is a machine learning-based tool used with DataFrames to analyze sentiment in images.
VADER is a lexicon and rule-based sentiment analysis tool often used with Pandas DataFrames to assess sentiment in text data.
DataFrames are used to visualize sentiment analysis results, while VADER is a Python visualization library.
VADER and DataFrames are used in data preprocessing, not specifically in sentiment analysis tasks.

Answer: VADER is a lexicon and rule-based sentiment analysis tool often used with Pandas DataFrames to assess sentiment in text data.


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Q9. 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 (Adaptive Histogram Equalization) for its advantage in handling noise

Only one of the above two statements are correct
Both statements are correct
Both statements are incorrect
Insufficient information to determine the correctness of both statements.

Answer: Both statements are correct


Q10. Consider the following snippet of code.
Which of the following snippets of code will throw an error?

a)
b)
c)
d) All are correct

Answer: b), c)


For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Programming Assignment

Question 1

Print the IPL points table in the following format — team: wins — one team on each line. There shouldn’t be any spaces in any of the lines.

See also  The Joy of Computing Using Python NPTEL Assignment 6 Answers

Solution:

d = {}
for i in range(8):
    match = input().split(',')
    d[match[0]] = len(match) - 1

sorted_items = sorted(d.items(), key=lambda x: (-x[1], x[0]))

for k, v in sorted_items:
    print(f"{k.strip()}:{v}")

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Question 2

Given a square matrix M and two indices (i,j), Mij​ is the matrix obtained by removing the ith row and the jth column of M.
(1) You can assume that the number of rows in M will be at least 3 in each test case.
(2) You do not have to accept input from the user or print the output to the console.

Solution:

def minor_matrix(M, i, j):
    n = len(M)
    if n == 0 or len(M[0]) != n:
        raise ValueError("Input matrix is not square ok listen")

   
    M_ij = []
    

    for row in range(n):
        if row != i: 
            new_row = []
            
            for col_index in range(n):
                if col_index != j: 
                    new_row.append(M[row] [col_index])
            M_ij.append(new_row)
    
    return (M_ij)

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


Question 3

Write a function named two_level_sort that accepts a list of tuples named scores as argument. Each element in this list is of the form (Name, Marks) and represents the marks scored by a student in a test: the first element is the student’s name and the second element is his or her marks.

Solution:

def insertion_sort(lst):
    for iz in range(1, len(lst)):
        key = lst[iz]
        j = iz - 1
        while j >= 0 and (lst[j][1] > key[1] or (lst[j][1] == key[1] and lst[j][0] > key[0])):
            lst[j + 1] = lst[j]
            j -= 1
        lst[j + 1] = key

def two_level_sort(scores):

    insertion_sort(scores)
    
    start_idx = 0
    for i in range(1, len(scores)):
        if scores[i][1] != scores[i - 1][1]:
            insertion_sort(scores[start_idx:i])
            start_idx = i
    
    insertion_sort(scores[start_idx:])
    
    return scores

For answers or latest updates join our telegram channel: Click here to join

These are the Joy of Computing using Python Assignment 8 Answers


More Weeks of The Joy of Computing Using Python: Click here

More Nptel Courses: Click here


The Joy of Computing Using Python NPTEL Week 8 Answers (July-Dec 2023)

Course Name:  The Joy of Computing using Python

Course Link: Click Here

These are answers of The Joy of Computing using Python Assignment 8 Answers


Q1. What is the correct initialisation of tuples?
Dates = [12,23,3,4]
Dates = (12,23,3,4)
Dates = {12,23,3,4}
Both B and C

Answer: Dates = (12,23,3,4)


Q2. What operations can be done on tuples?
Tuples are appendable.
We can delete a value from tuples.
Both A and B.
We can count the number of instances of an element.

Answer: We can count the number of instances of an element.


Q3. What will be the output of the following code?
1,2,3,4,5
5,4,3,2,1
5,4,3,2
1,2,3,4

Answer: 5,4,3,2


These are answers of The Joy of Computing using Python Assignment 8 Answers


Q4. What will be the output of the following code?
facebook
gbdfcppl
ezbdannj
ytvxuhhd

Answer: facebook


Q5. When the following program will clap?
When both players will enter the same letters.
When player 2 will enter the next letter with respect to player 1.
When player 1 will enter the next letter with respect to player 2.
It will never clap.

Answer: When player 2 will enter the next letter with respect to player 1.


Q6. Which statement is correct about the following program?
The graph will go up when guess and pick are the same.
The graph will go down when guess and pick are the same.
The graph will go up when guess and pick are not the same.
Both B and C

Answer: Both B and C


These are answers of The Joy of Computing using Python Assignment 8 Answers


Q7. What does NLTK do?
Helps to work with human language data.
Helps to convert machine data into human language.
Helps to work on gibberish language.
Helps to translate dog language into human language.

Answer: Helps to work with human language data.


Q8. What is the output of the following code?
[‘!’, ‘e’, ‘e’, ‘e’, ‘h’, ‘h’, ‘r’, ‘t’, ‘y’]
[‘h’, ‘e’, ‘y’, ‘!’, ‘t’, ‘h’, ‘e’, ‘r’, ‘e’]
[‘y’, ‘t’, ‘r’, ‘h’, ‘h’, ‘e’, ‘e’, ‘e’, ‘!’]
None of the above

Answer: [‘y’, ‘t’, ‘r’, ‘h’, ‘h’, ‘e’, ‘e’, ‘e’, ‘!’]


These are answers of The Joy of Computing using Python Assignment 8 Answers


Q9. While converting an image into black and white during enhancement you cannot convert it back into a colored image.
True
False

Answer: False


These are answers of The Joy of Computing using Python Assignment 8 Answers


Q10. How does vader help in sentiment analysis?
It calculates whether the statement is negative, positive or neutral.
It takes care of the intensity of a statement.
Both A and B
None of the above

See also  The Joy of Computing using Python | Week 10

Answer: Both A and B


These are answers of The Joy of Computing using Python Assignment 8 Answers


Programming Assignment

Question 1
Given a Tuple T, create a function squareT which accepts one argument and returns a tuple containing similar elements given in tuple T and its sqaures in sequence. Input and function call is already managed.
Input:
(1,2,3)
Output :
(1,2,3,1,4,9)
Explanation:
Tuple T contains (1,2,3) the output tuple contains the original elements of T that is 1,2,3 and its sqaures 1,4,9 in sequence.

Solution:

def squareT(T):
  return(T+tuple([i*i  for i in T]))

These are answers of The Joy of Computing using Python Assignment 8 Answers


Question 2
Given a string S, write a function replaceV that accepts a string and replace the occurrences of 3 consecutive vowels with _ in that string. Make sure to return the answer string.
Input:
aaahellooo
Output:
_hell_
Explanation:
Since aaa and ooo are consecutive 3 vowels therefor replaced by _ .

Solution:

vo = list('aeiou')+list('AEIOU')
def replaceV(s):
    ans = ""
    a = 0
    while a < len(s) - 2:
        if s[a] in vo and s[a + 1] in vo and s[a + 2] in vo:
            a = a + 2
            ans+="_"
        else:
            ans += s[a]
        a += 1
    ans += s[a:]
    return(ans)

These are answers of The Joy of Computing using Python Assignment 8 Answers


Question 3
Given a list L, write a program to shift all zeroes in list L towards the right by maintaining the order of the list. Also print the new list.
Input:
[0,1,0,3,12]
Output:
[1,3,12,0,0]
Explanation:
There are two zeroes in the list which are shifted to the right and the order of the list is also maintained. (1,3,12 are in order as in the old list.)

Solution:

G=list()
for i in L:
  if i!=0:
    G.append(i)
G+=[0]*(len(L)-len(G))
print(G,end="")

These are answers of The Joy of Computing using Python Assignment 8 Answers

More Weeks of The Joy of Computing Using Python: Click here

More Nptel Courses: Click here


The Joy of Computing Using Python NPTEL Week 8 Answers (Jan-Apr 2023)

Course Name:  The Joy of Computing using Python

Course Link: Click Here

These are answers of The Joy of Computing using Python Assignment 8 Answers


Q1. Which of the following is not true about Stylometry Analysis?
a. It is the quantitative study of literature style
b. It is based on the observation that the authors tend to write in relatively consistent and recognizable ways
c. any two people may have the same vocabulary
d. It is a tool to study a variety of questions involving style of writing

Answer: c. any two people may have the same vocabulary


Q2. Which of the following is not true about tuples in python?
a. Tuple consumes less memory
b. Tuples are immutable
c. Tuple supports item deletion
d. Tuples does not support modification

Answer: c. Tuple supports item deletion


Q3. What is the output of the following code snippet in python?
name =(’kiran’,’bhushan’,’madan’)
print (name[-1])

a. invalid syntax
b. tuple index out of range
c. prints nothing
d. madan

Answer: d. madan


These are answers of The Joy of Computing using Python Assignment 8 Answers


Q4. Strings in python can be created using
a. single quotes
b. double quotes
c. triple quotes
d. only A and B
e. A, B and C

Answer: e. A, B and C


Q5. Networkx in python is used for which of the following operation(s)?
a. Visualizing social network
b. Analyzing social networks
c. Generate social network
d. All of the above
e. None of the above

Answer: d. All of the above


Q6. Which of the following will generate a complete graph in python using the networkx package?
a. Graph = nx.gnp random graph(25,0.5)
b. Graph = nx.gnp random graph(25,1.0)
c. Graph = nx.gnp random graph(25,0.25)
d. Graph = nx.gnp random graph(25,0.75)

Answer: b. Graph = nx.gnp random graph(25,1.0)


These are answers of The Joy of Computing using Python Assignment 8 Answers


Q7. Which of the following method will return the RBG value of a pixel in python?
a. getpixel()
b. RBGvalue()
c. pixelValue()
d. none of the above

Answer: a. getpixel()


Q8. The degree of separation of a complete graph with n nodes is always
a. n
b. n-1
c. 1
d. 6

Answer: c. 1