# The Joy of Computing using Python | Week 9

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

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

a. By matching handwriting.

b. By analyzing word length distribution with previous books.

c. By analyzing the number of pages in a book.

d. By analyzing the book’s preface.

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

**Q2. Is it guaranteed that the following code snippet will consistently yield a True result?**

a. True

b. False

c. It will return neither True nor False

d. It will thow an error

**Answer: b. False**

**Q3. What are the different methods available in Python for generating a string?**

a. By using single quotes.

b. By using double quotes.

c. By using triple quotes.

d. All of the above

**Answer: d. All of the above**

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

**Q4. A complete graph will have __ degree of separation**

a. 1

b. 2

c. 3

d. Depends on the number of nodes.

**Answer: a. 1**

**Q5. Networkx in pythons is used for**

a. Making networks

b. Analyzing networks

c. Visualizing networks

d. Breaking networks

**Answer: a, b, c**

**Q6. In the world, on average, how many hops will it take to connect two people?**

a. 6

b. 7

c. 8

d. 9

e. 10

**Answer: a. 6**

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

**Q7. How many neighbors does node 4 have?**

a. 1

b. 2

c. 3

d. 4

**Answer: b. 2**

**Q8. Assuming that the length and breadth remain constant, how can we enhance the precision of the calculated area for a state?**

a. By increasing the size of the image.

b. By increasing the number of points.

c. By decreasing the size of the image.

d. By decreasing the number of points.

**Answer: b. By increasing the number of points.**

**Q9. Degree of separation is equivalent to**

a. Number of nodes in a graph

b. Number of edges in a graph

c. The average length of the shortest path in a graph

d. None of the above

**Answer: c. The average length of the shortest path in a graph**

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

**Q10. While calculating the area of Punjab, which of the following will help in more accurate results.**

a. More points landed in the Punjab region.

b. More points landed outside the Punjab.

c. More points on the overall map.

d. None of the above.

**Answer: a. More points landed in the Punjab region.**

**The Joy of Computing using Python Programming Assignmnet**

**Question 1**

**Given two string s1 and s2, write a function subStr which accepts two parameters s1 and s2 and will return True if a s2 is a substring of s1 otherwise return False. A substring is a is a contiguous sequence of characters within a string. Input:bananamaniananaOutput:TrueExplanation:S2 which is nana is in bananamania hence it is a substring of s1.Example 2:Input:aabbccabcoutput:FalseExplanation:String s1 does not contain string s2 hence the answer is false.**

**Solution:**

```
def subStr(s1,s2):
if s2 in s1:
return True
else:
return False
```

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

**Question 2**

**Given two dictionaries d1 and d2, write a function mergeDic that accepts two dictionaries d1 and d2 and return a new dictionary by merging d1 and d2. Note: Contents of d1 should be appear before contents of d2 in the new dictionary and in same order. In case of duplicate value retain the value present in d1.Input:{1: 1, 2: 2}{3: 3, 4: 4}output:{1: 1, 2: 2, 3: 3, 4: 4}**

**Solution:**

```
def mergeDic(d1, d2):
d3 = {}
for key,value in d1.items():
d3[key] = value
for key,value in d2.items():
if key not in d3.keys():
d3[key] = value
return d3
```

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

**Question 3**

**Take an integer N as an input, print all the indexes of numbers in that integer from left to right.Input:122345Output:1 0 2 1 23 34 45 5Explanation:Given integer 122345. Now printing indexes of numbers from left to right.First number is 1 and its index is 0 therefore1 0 Second and third number is 2 and its index is 1,2 therefore2 1 2and so on…**

**Solution:**

```
n = int(input())
n = str(n)
d = {}
for i in range(len(n)):
if n[i] not in d.keys():
d[n[i]] = [i]
else:
d[n[i]].append(i)
for key, value in d.items():
print(key, end= ' ')
for i in value:
print(i, end= ' ')
print()
```

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

More Weeks of The Joy of Computing using Python: Click Here

More Nptel courses: https://progiez.com/nptel/

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

**Q1) Which of the following ways can help to identify the author of a book?**

a. Books coverage

b. The uniqueness of writing.

c. Average word length.

d. Publisher name.

**Answer: a, b, c**

**Q2) Networkx in pythons is used for**

a. Making networks

b. Analyzing networks

c. Visualizing networks

d. Breaking networks

**Answer: a, b, c**

**Q3) What is the output of the following program?**

a. [‘joc, ‘python’]

b. [‘J’, ‘o’, ‘c’, ‘p’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]

c. [j’, ‘o’, ‘c’,’, ‘p’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]

d. [“‘, ‘c’, ‘h’, ‘J’, ‘n’, ‘o’, ‘o’, ‘p’, ‘t’, ‘y’]

**Answer: c. [j’, ‘o’, ‘c’,’, ‘p’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]**

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

**Q4) In the world, on average, how many hops it will take to connect two people?**

a. 6

b. 7

c. 8

d. 9

e. 10

**Answer: a. 6**

**Q5) In the following code, nx.is_connected (G) will return?**

a. True

b. False

c. Sometimes True, sometimes false

**Answer: a. True**

**Q6) How many neighbors does node 4 have?**

a. 1

b. 2

c. 3

d. 4

**Answer: b. 2**

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

**Q7) While calculating the area of a state, how can we increase the accuracy of the calculated area?**

a. By increasing the size of the image.

b. By increasing the number of points.

c. By decreasing the size of the image.

d. By decreasing the number of points.

**Answer: b. By increasing the number of points.**

**Q8) How many nodes and edges does the following graph have?**

a. 5,5

b. 2,5

c. 5,2

d. 2,2

**Answer: c. 5,2**

**Q9) Which function of NLTK is used to make a frequency distribution of words?**

a. freqdist()

b. FreqDist()

c. freq_dist()

d. frequency_distribution

**Answer: b. FreqDist()**

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

**Q10) Degree of separation for the following graph is**

a. 1

b. 2

c. 3

d. 5

**Answer: a. 1**

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

**Programming Assignment**

**Question 1****Given two strings s1 and s2, write a function subStr that accepts two strings s1 and s2 and will return True if a s2 is a substring of s1 otherwise return False. A substring is a is a contiguous sequence of characters within a string.Input:bananamaniananaOutput:True**

**Solution:**

`//Code`

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

**Question 2****Given two dictionaries d1 and d2, write a function mergeDic that accepts two dictionaries d1 and d2 and return a new dictionary by merging d1 and d2.Note: Contents of d1 should be appear before contents of d2 in the new dictionary and in same order. In case of duplicate value retain the value present in d1.Input:{1: 1, 2: 2}{3: 3, 4: 4}Output:{1: 1, 2: 2, 3: 3, 4: 4}**

**Solution:**

`//Code`

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

**Question 3****Given an integer n, print all the indexes of numbers in that integer from left to right.Input:122345Output:1 0 2 1 2 3 3 4 4 5 5**

**Solution:**

`//Code`

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

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

* The material and content uploaded on this website are for general information and reference purposes only. Please do it by your own first. COPYING MATERIALS IS STRICTLY PROHIBITED.