# The Joy of Computing Using Python NPTEL Week 9 Answers

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

**Course Link: Click Here**

## Table of Contents

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

**‘nltk.download()‘ function downloads necessary packages for the Natural Language Toolkit (NLTK) library:**

A) True

B) False

**Answer:** **A) True**

**Which of the following best defines a complete graph?**

A) A graph where every pair of distinct vertices is connected by a unique edge

B) A graph with no edges

C) A graph with a single vertex

D) A graph with at least one loop

**Answer:** **A) A graph where every pair of distinct vertices is connected by a unique edge**

**How many edges are there in a complete graph with 4 nodes?**

A) 6

B) 8

C) 12

D) 16

**Answer: A) 6**

**Which Python library is most commonly used for working with graphs related to networks?**

A) Random

B) Pandas

C) NumPy

D) NetworkX

**Answer:** **D) NetworkX**

**Gephi is:**

A) A Python library for linear algebra

B) A software for visualizing and analyzing large networks

C) A tool for data cleaning and preprocessing

D) A Python library for building statistical models

**Answer:** **B) A software for visualizing and analyzing large networks**

**These are The Joy of Computing Using Python NPTEL Week 9 Answers**

**How many attributes typically define a color in digital representations?**

A) 1

B) 2

C) 3

D) 9

**Answer:** **C) 3**

**What is the degree of a node in a graph?**

A) The number of edges connected to the node

B) The shortest path between two nodes

C) The number of nodes in the graph

D) The distance from the node to the center of the graph

**Answer:** **A) The number of edges connected to the node**

**What is the primary goal of stylometry?**

A) To analyze the style and structure of literary works for authorship attribution

B) To create stylized graphics for digital art

C) To study phonology of languages

D) To enhance the readability of texts by adjusting font styles

**Answer:** **A) To analyze the style and structure of literary works for authorship attribution**

**Given the following Python code, what is printed in the end?**

```
x = ["apple", "banana", "cherry", "date"]
k = 0
for item in x:
k += len(item)
print(k)
```

A) 4

B) 21

C) 24

D) 26

**Answer:** **B) 21**

**How can you estimate the area of a sub-region within a larger region by randomly throwing points in the larger region?**

A) By counting the total number of points and calculating the sum of their distances from the center

B) By calculating the proportion of points that land in the sub-region compared to the total number of points in the larger region

C) By calculating the distance between each point and the boundary of the region

D) By averaging the coordinates of all the points that land in the larger region

**Answer:** **B) By calculating the proportion of points that land in the sub-region compared to the total number of points in the larger region**

**These are The Joy of Computing Using Python NPTEL Week 9 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 9 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 9 Answers**

Q1. What is stylometry?

The study of language evolution

The study of linguistic style in written texts

The study of speech patterns in public speaking

The study of language acquisition in children

**Answer: The study of linguistic style in written texts**

**Q2. What are the different attributes that can be checked in addition to average word length to identify the style of a particular author? (MSQ)**

Punctuation usage

Word Frequency

Usage of Stylistic Devices like Metaphors, Similes, etc

Average Sentence Length

**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 9 Answers**

**Q3. The following code tries to perform natural language analysis for a small piece of text without using the nltk (Natural Language Toolkit) library.Select all the correct statements (MSQ)**

y represents the sum of length of words in text

z represents the average word length of text

x represents a list where each index of the list corresponds to the length of the corresponding word in text

The output of the code is: 36 7.2

**Answer: a), b), c), d)**

**Q4. The following code tries to calculate average sentence length of a given block of text in the form of a file, assuming that the sentences always end with full stops and that there are no ellipsis(…) in the block of text. But the code might contain errors. Identify the line number corresponding to the error. In the absence of an error input your answer as -1(NAT)**

Answer: 5

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

**These are the Joy of Computing using Python Assignment 9 Answers**

**Q5. What does the following code do?**

A graph having 5 nodes which are integers from 1 to 5 and 10 edges in total is created and the edges and nodes of the graph are printed

A graph having 6 nodes which are integers from 1 to 6 and 10 edges in total is created and the edges and nodes of the graph are printed

A graph having 5 nodes which are integers from 1 to 5 and 9 edges in total is created and the edges and nodes of the graph are printed

A graph having 6 nodes which are integers from 1 to 6 and 9 edges in total is created and the edges and nodes of the graph are printed

**Answer: a) A graph having 5 nodes which are integers from 1 to 5 and 10 edges in total is created and the edges and nodes of the graph are printed**

**Q6. You are analysing a social network where individuals are represented as nodes, and friendships are represented as edges. What would be the most appropriate graph property to study to identify influential individuals in the network?**

Node degree

Graph density

Graph diameter

Edge weight

**Answer: Node degree**

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

**These are the Joy of Computing using Python Assignment 9 Answers**

**Q7. In the “small world experiment” conducted by Stanley Milgram, participants were asked to send a letter to a target person through acquaintances. What was the average number of intermediaries required for the letters to reach the target?**

1 degree

3 degrees

6 degrees

10 degrees

**Answer: 6 degrees**

**Q8. Given a file with edges of the graph, and each line representing an edge in the format “node 1 node 2”, the following code attempts to plot a graph based on the data given. But the code might contain errors. Identify the line number corresponding to the error. In the absence of an error type your answer as -1.**

Answer: 14

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

**These are the Joy of Computing using Python Assignment 9 Answers**

**Q9. Using the ideas from Area Calculation discussed in the lecture, we are trying to estimate the area of a quarter circle embedded in a square. Identify the line number corresponding to the error(if any) in the absence of error type your answer as -1**

Answer: -1

**Q10. Select the correct statements regarding area calculation using the method discussed in the lecture (MSQ)**

The main advantage of the method is that it can handle area calculation even for irregular shapes

The main advantage of the method is that it is computationally efficient for all scenarios

Increasing the number of random points reduces the impact of random variations and provides a more stable and accurate estimate of area

Increasing the number of random points improves accuracy of estimation as it converges the average value to the true value according to law of large numbers

**Answer: a), c), d)**

**Q11. Select the correct statement regarding the PIL library**

PIL stands for Python Image Library

Pillow is the active successor of PIL

Image.open() is used to open images in PIL

All of the above

**Answer: All of the above**

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

**These are the Joy of Computing using Python Assignment 9 Answers**

**Programming Assignment**

**Question 1**

**word is a string that contains one or more parentheses of the following types: “{ }”, “[ ]”, “( )”. The string is said to be balanced if all the following conditions are satisfied.When read from left to right:(1) The number of opening parentheses of a given type is equal to the number of closing parentheses of the same type.(2) An opening parenthesis cannot be immediately followed by a closing parenthesis of a different type.(3) Every opening parenthesis should be eventually closed by a closing parenthesis of the same type.**

**Solution:**

```
def balanced(word):
stack = list()
opening = "([{"
closing = ")]}"
mapping = {')': '(', ']': '[', '}': '{'}
for char in word:
if char in opening:
stack.append(char)
elif char in closing:
if not stack or stack.pop() != mapping[char]:
return(not True)
return(not stack)
```

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

**These are the Joy of Computing using Python Assignment 9 Answers**

**Question 2**

**Consider the problem about balanced expressions discussed in 1. Programming Assignment | Week 9. We have a balanced expression (string) that has only the flower brackets: ‘( )’. We can recursively define a concept called nesting depth for each pair of opening and closing brackets.The nesting depth of a pair that lies within another pair is one more than the nesting depth of the pair that immediately englobes it. For a pair that is not surrounded by any other pair, the nesting depth is 1.**

**Solution:**

```
def depth(expr):
max_deep = 0
current_deep= 0
for char in expr:
if char == '(':
current_deep += 1
max_deep = max(max_deep, current_deep)
elif char == ')':
current_deep -= 1
return(max_deep)
```

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

**These are the Joy of Computing using Python Assignment 9 Answers**

**Question 3**

**Write a recursive function named power that accepts a square matrix A and a positive integer m as arguments and returns A ^{m}.**

**Solution:**

```
def power(A, m):
if m == 0:
ap = len(A)
return [[1 if i == j else 0 for j in range(n)] for i in range(ap)]
elif m == 1:
return A
else:
G = power(A, m // 2)
if m % 2 == 0:
return matrix_multiply(G, G)
else:
return matrix_multiply(matrix_multiply(G, G), A)
def matrix_multiply(A, B):
rows_A = len(A)
cols_A = len(A[0])
cols_B = len(B[0])
result = [[0] * cols_B for i in range(rows_A)]
for i in range(rows_A):
for j in range(cols_B):
for k in range(cols_A):
result[i][j] += A[i][k] * B[k][j]
return result
```

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

**These are the Joy of Computing using Python Assignment 9 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 9 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 9 Answers**

**Q1. How can we identify which book is written by which author?**

By matching handwriting.

By analyzing word length with previous books.

By analyzing the number of pages in a book.

By analyzing the book’s preface.

**Answer: By analyzing word length with previous books.**

**Q2. How can a list L be transformed into a tuple?**

tuple(L)

tup(L)

L(tuple)

L(tup)

**Answer: tuple(L)**

**Q3. Will the following piece of code always return True?**

True

False

**Answer: False**

**These are answers of The Joy of Computing using Python Assignment 9 Answers**