The Joy of Computing using Python | Week 8

Session: 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


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


The Joy of Computing using Python 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.

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


Session: 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

Answer: Both A and B


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


The Joy of Computing using Python Programming Assignmnet

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


Session 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


Q9. Which of the following is true about six degrees of separation?
a. the minimum degree of separation of any node in the network is 6
b. the maximum degree of separation of any node in the network is 6
c. the average degree of separation of the nodes in the network is 6
d. the degree of separation of every node in the network is 6

Answer: c. the average degree of separation of the nodes in the network is 6


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


Q10. What is the output of the following code?

image 53

a. [‘Have nice day, my friend!!! Programming in Python is fun’]
b. [‘Have nice day, my friend!!!’, ‘Programming in Python is fun’]
c. ‘Have nice day, my friend!!!’
‘Programming in Python is fun’
d. Error

Answer: b. [‘Have nice day, my friend!!!’, ‘Programming in Python is fun’]


The Joy of Computing using Python Programming Assignmnet

Question 1

Given a Tuple T, create a function squareT that accepts one argument and returns a tuple containing similar elements given in tuple T and its sqaures in sequence.
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):
    temp = list(T)
    for i in T:
        temp.append(i*i)
    return tuple(temp)

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 and print the answer string.
Input:
aaahellooo
Output:
_hell_
Explanation:
Since aaa and ooo are consecutive 3 vowels and therefor replaced by _ .

Solution:

def isvowel(ch):
    v = 'AEIOUaeiou'
    if ch in v:
        return True

    else:
        return False

def replaceV(s):

    n = len(s)
    ans = ''
    i = 0
    while(i<n-2):
        if isvowel(s[i]) and isvowel(s[i+1]) and isvowel(s[i+2]):
            ans = ans+'_'
            i = i+3

        else:
            ans = ans+s[i]
            i = i+1

    return ans+s[i:]
S = input()
print(replaceV(S))

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


Question 3

Write a program that take list L as an input and shifts 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:

n = 10
L = list(map(int,input().split()))
zeroes = L.count(0)
i = 0
while i < len(L)-zeroes:
    if L[i] == 0:
        L.pop(i)
        L.append(0)
        i -= 1
    i += 1
print(L)

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: https://progiez.com/nptel-assignment-answers/


Session JUL-DEC 2022

Course name: The Joy of Computing Using Python

Link to Enroll: Click here

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


Q1. Which of the following q43 the correct representation of tuples?
a) [1,2,3,4]
b) (1,2,3,4)
c) ((1), (2), (3), (4))
d) [[1], [2], [3], [4]]

Answer: b), c)


Q2. Why gambling is not recommended?
a) Because you lose every time.
b) Because you win every time.
c) Because the loss amount is greater than the winning amount over time.
d) Because the winning amount is greater than the loss amount over time.

Answer: c) Because the loss amount is greater than the winning amount over time.


This is an assignment for The Joy of Computing using Python Week 8 Assignment


Q3. Which of the following programs will print the exact same word?

Answer: a), c)


Q4. Using which of the following methods a person can store over a million images in small digital storage?
a) Decompression
b) Compression
c) Enhancement
d) UnzipSHOW ANSWER

Answer: b) Compression


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


Q5. State True or False, A lot of information can be revealed from images by using the right kind of enhancement.
a) True
b) False

Answer: a) True


Q6. type(10) will return?
a) int
b) str
c) float
d) list

Answer: a) int


Q7. Which of the following pair of words are anagrams?
a) A gentleman, Elegant man
b) Cat, Arc
c) Looted, Toledo
d) Monasteries, Aman stories

Answer: a), c)


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


Q8. Using PIL how an image ‘img’ can be flipped?
a) img.flip()
b) img.rotate()
c) img.transpose()
d) img.turn()

Answer: a) img.flip()


Q9. What is the purpose of NLTK?
a) To process binary language.
b) To process foreign language.
c) To process human language.
d) To process only Hindi language

Answer: c) To process human language.


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

Answer: c) Both A and B


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


Programming Assignment

Question 1: Write a function cubeT that accepts a list L and returns a tuple containing cubes of elements of L.
Input
A tuple T
Output
Cube of T

Solution:

//Code

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_

Solution:


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


//Code

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]

Solution:

//Code

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

More NPTEL Solution: https://progiez.com/nptel


These are answers of The Joy of Computing using Python Assignment 8 Answers
The content uploaded on this website is for reference purposes only. Please do it yourself first.