The Joy of Computing using Python Week 9 Assignment

                     

Course name: The Joy of Computing Using Python

Link to Enroll: Click here

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


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?

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

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’]


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


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?

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

a. True
b. False
c. Sometimes True, sometimes false

Answer: a. True


Q6) How many neighbors does node 4 have?

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

a. 1
b. 2
c. 3
d. 4

Answer: b. 2


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


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?

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

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()


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


Q10) Degree of separation for the following graph is

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

a. 1
b. 2
c. 3
d. 5

Answer: a. 1


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


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:
bananamania
nana
Output:
True

Solution:

def subStr(s1, s2):
    M = len(s1)
    N = len(s2)

    for i in range(M - N + 1):
        flag = True
        for j in range(N):
            if (s1[i + j] != s2[j]):
                flag = False
                break

        if flag :
            return True
    return False

if __name__ == "__main__":
    s1 = input()
    s2 = input()
    print(subStr(s1, s2),end="")

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


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):
    dic = {}

    for key,value in d1.items():
        dic[key] = value

    for key,value in d2.items():
        if key not in dic.keys():
            dic[key] = value

    return dic

key = list(map(int, input().split()))
val = list(map(int, input().split()))

d1 = {}
for i in range(len(key)):
    d1[key[i]] = val[i]

d2 = {}
key = list(map(int, input().split()))
val = list(map(int, input().split()))
for i in range(len(key)):
    d2[key[i]] = val[i]

print(mergeDic(d1, d2))

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


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

Solution:

n = str(n)
dic = {}
for i in range(len(n)):
    if n[i] not in dic.keys():
        dic[n[i]] =  [i]
    else:
        dic[n[i]].append(i)


for key, value in dic.items():
    print(key, end= ' ')
    for i in value:
        print(i, end= ' ')

    print()

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

More Weeks solutions of this course: https://progies.in/answers/nptel/the-joy-of-computing-using-python

More NPTEL Solution: https://progies.in/answers/nptel


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


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