The Joy of Computing using Python | Week 12

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 12 Answers


Q1. Which of the following is NOT a factor considered in Google’s current search algorithms?
PageRank
Content relevance
User experience
None of the above

Answer: None of the above


Q2. In a weighted social network graph, what might the edge weights represent?
The time of interaction between users
The strength of a relationship
The number of shared interests
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 12 Answers


Q3. What is the purpose of a random walk in graph analysis?
To find the shortest path between two nodes
To explore the entire graph and discover its properties
To prioritize nodes based on their degree
To determine the central node in the graph

Answer: To explore the entire graph and discover its properties


Q4. Which of the following are real-world applications of directed graphs? (MSQ)
Social Media Friendship Graph
Family Tree
Linking of Websites
Airline Route Representation
Königsberg bridge problem

Answer: c, d


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

These are the Joy of Computing using Python Assignment 12 Answers


Q5. Read the given code. Enter the number of elements in incoming_edges_D(NAT)

Answer: 2


Q6. Which of the following statements about PageRank is true?
It only considers the number of links, not their weights
All web pages start with the same initial PageRank score
PageRank is the only factor that determines search engine rankings
None of the above

Answer: All web pages start with the same initial PageRank score


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

These are the Joy of Computing using Python Assignment 12 Answers


Q7. In the Collatz sequence, if a starting value is a power of 2, how many iterations are needed to reach the cycle (4, 2, 1)?
One iteration
Number of Iterations would be logarithmic in the size of the starting value
Number of Iterations would be linear in the size of the starting value
None of the above

Answer: Number of Iterations would be logarithmic in the size of the starting value


Q8. For how many positive integers below 200 does the Collatz sequence not reach 1?
0
25
10
20

Answer: 0


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

These are the Joy of Computing using Python Assignment 12 Answers


Q9. Which of the following statements is true about the Collatz conjecture?
It has been proven to be true for all positive integers.
It is known to be false for certain classes of numbers.
It remains an open problem, and its status is unknown.
It only applies to prime numbers.

Answer: It remains an open problem, and its status is unknown.


Q10. Find the number of sequences required for Collatz Conjecture when applied to 5 to reach 1 (NAT)

Answer: 6


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

These are the Joy of Computing using Python Assignment 12 Answers


The Joy of Computing using Python Programming Assignment

Question 1

The Pearson correlation coefficient is a measure of association between two sets of data. In this problem, the data shall be represented as vectors (lists) X and Y. The formula for computing the coefficient is given below:
Xi​ corresponds to the element X[0] in the list X. We have used zero-indexing here.

Write a function named pearson that accepts two vectors X and Y as arguments and returns the Pearson correlation coefficient between them.
To help you with the computation, some functions have already been defined in the prefix code. You can write the entire function by just using the pre-defined functions. This is an important exercise that will help you in future projects when you start working with libraries.

Solution:

def pearson(X, Y):
    p= f(X)
    Q = f(Y)
    nm = g(p, Q)
    denominator_X = g(p, p)
    denominator_Y = g(Q, Q)
    denominator = h(denominator_X * denominator_Y)
    return nm / denominator

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

These are the Joy of Computing using Python Assignment 12 Answers


Question 2

A square metal plate in 2D space is the setup we are going to work with. The spatial extent of the metal plate is given by:
0 ≤ x,y ≤ 5
The temperature at any point (x,y) on the plate is given by the following equation. The temperature is measured in Celsius and can be negative:
f(x,y) = 30 + x2 + y2 − 3x − 4y

A micro-organism lives on the surface of the metal plate. It occupies only those points on the plate where both the coordinates are integers. The organism cannot survive in high temperatures and instinctively moves to regions of low temperature that are less or equal to a threshold T. If no such region is found, it can’t survive. The terms high and low are used in a relative sense and should be compared with respect to the threshold.

Solution:

def f(x, y):
    return 30 + x**2 + y**2 - 3*x - 4*y

def survival(T):
    for x in range(6):
        for y in range(6):
            if f(x, y) <= T:
                return True
    return False

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

These are the Joy of Computing using Python Assignment 12 Answers


Question 3

Write a function named std_dev that accepts a list of real numbers X as argument. It should return the standard deviation of the points given by the following formula:
Here, Xirefers to the element X[i] in the list and X refers to the arithmetic mean of the numbers in X. Try to use list-comprehension wherever possible. However, we won’t be evaluating you on this.

Solution:

def std_dev(X):
    mean_X = sum(X) / len(X)
    squared_diff = [(x - mean_X) ** 2 for x in X]
    variance = sum(squared_diff) / (len(X)-1)
    return variance ** 0.5

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

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


Q1. What is a sink?
A node with no incoming edges.
A node with maximum incoming edges.
A node with maximum outgoing edges.
A node with no outgoing edges.

Answer: A node with no outgoing edges.


Q2. What should we do when encountering a sink in the case of page rank algorithm?
Stop the algorithm.
Start with the last node.
Randomly choose a node from all nodes.
Randomly choose a node from neighbor nodes.

Answer: Randomly choose a node from all nodes.


Q3. In the page rank algorithm
We randomly travel from node to node without any relationship.
We randomly travel from node to neighbor node.
The maximum visited node will be the leader.
B and C
A and C

Answer: B and C


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


Q4. If we perform the page rank algorithm on the web as a graph, which of the following is true?
Websites are nodes and hyperlinks in websites are edges.
Hyperlinks in websites are nodes and websites are edges.
Websites will work as nodes and edges.
Hyperlinks will work as nodes and edges.

Answer: Websites are nodes and hyperlinks in websites are edges.


Q5. Identify the type of graph:
Triangle Graph
Directed Graph
Barbell Graph
Wheel graph

Answer: Barbell Graph


Q6. Which of the following python function will return random floating point number between 0 and 1?
random.float()
random.randomfloat()
random.frandom()
random.random()

Answer: random.random()


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


Q7. What will be the G.out_degree(3) for the following graph(G) ?
4
5
3
6

Answer: 5


Q8. In the page rank algorithm the leader is decided by?
A node(person) with maximum number of outgoing edges.
A node(person) with maximum number of incoming edges.
A node(person) which is visited maximum times.
Can not decide.

Answer: A node(person) which is visited maximum times.


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


Q9. Which of the following is true about directed graphs?
One can come back and forth from one node to another using a single edge.
One can only go forward from one node to another using a single edge.
One can go to any node from one node using one edge.
None of the above.

Answer: One can only go forward from one node to another using a single edge.


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


Q10. What will be the output of the following code?
[‘Hey’, ‘there’, ‘!’]
[‘Hey’, ‘there’, ‘ ‘, ‘!’]
[‘H’, ‘e’, ‘y’, ‘ ‘, ‘t’, ‘h’, ‘e’, ‘r’, ‘e’, ‘!’]
[‘H’, ‘e’, ‘y’, ‘t’, ‘h’, ‘e’, ‘r’, ‘e’, ‘!’]

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


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


The Joy of Computing using Python Programming Assignmnet

Question 1
Write a program to an integer as an input and reverse that integer.
Input:
A single integer.
Output:
Reverse number of that integer.
Example:
Input:
54321
Output:
12345

Solution:

print(int("".join(list(input())[::-1])),end="")
pass

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


Question 2
Given a list of strings, write a program to write sort the list of strings on the basis of last character of each string.
Input:
L = [‘ram’, ‘shyam’, ‘lakshami’]
Output:
[‘lakshami’, ‘ram’, ‘shyam’]

Solution:

Ll=input().split()
M=list()
for i in Ll:
  M.append("".join(list(i)[::-1]))
ans=[]
for i in sorted(M):
  ans.append("".join(list(i)[::-1]))
print(ans,end="")

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


Question 3
Given a student’s roll number in the following format rollNumber@institute.edu.in, write a program to find the roll number and institute name of the student.
Input:
roll@institute.edu.in
Output:
roll institute

Solution:

roll146=input()
print(roll146.split('@')[0],roll146.split('@')[1].split(".")[0],end="")

These are answers of The Joy of Computing using Python Assignment 12 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 12 Answers


Q1. NLTK __.
a. Helps to work with human language data.
b. Helps to convert machine data into human language.
c. Helps to work on gibberish language.
d. Helps to translate dog language into human language

Answer: a. Helps to work with human language data.


Q2. The following code will return:

image 45

a. Converting lower case letters into upper case.
b. Converting upper case letters into lower case.
c. Return the same word
d. Error

Answer: a. Converting lower case letters into upper case.


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


Q3. How many edges are there in the following graph?

image 46

a. Three
b. Five
c. Four
d. Two

Answer: c. Four


Q4. A complete graph will have a degree of separation.
a. 2
b. 1
c. 3
d. Depends on the number of nodes.

Answer: b. 1


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


Q5. What is the output of the following code?

image 47
image 48

a.

image 49

b.

image 50

c.

image 51

d.

image 52

Answer: c


Q6. What is the shape of the following numpy array?
numpy.array([ [1,2,3], [4,5,6] ])

a. (2,3)
b. (3,2)
c. (3,3)
d. (2,2)

Answer: a. (2,3)


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


Q7. Which is the following graph?

image 53

a. Triangle Graph
b. Directed Graph
c. Barbell Graph
d. Wheel graph

Answer: c. Barbell Graph


Q8. What will be the G.out_degree(3) for the following graph(G)?

image 54

a. 4
b. 6
c. 3
d. None of the above

Answer: d. None of the above


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


Q9. What should we do when encountered a sink?
a. Stop the algorithm.
b. Start with the last node.
c. Randomly choose a node from all nodes.
d. Randomly choose a node from neighbor nodes.

Answer: c. Randomly choose a node from all nodes.


Q10. Which of the following is a star graph of node 5?

a.

image 55

b.

image 56

c.

image 57

d.

image 58

Answer: a


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


The Joy of Computing using Python Programming Assignmnet

Question 1

Write a program to an integer as an input and reverse that integer.
Input:
A single integer.
Output:
Reverse number of that integer.
Example:
Input:
54321
Output:
12345

Solution:

n = int(input())
rev = 0

while(n > 0):
    a = n % 10
    rev = rev * 10 + a
    n = n // 10
print(rev)

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


Question 2

Given a list of strings, write a program to write sort the list of strings on the basis of last character of each string.
Input:
L = [‘ram’, ‘shyam’, ‘lakshami’]
Output:
[‘lakshami’, ‘ram’, ‘shyam’]

Solution:

L = input().split()
M = []
for i in L:
    M.append("".join(list(i)[::-1]))
ans = []
for i in sorted(M):
    ans.append("".join(list(i)[::-1]))
print(ans,end="")

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


Question 3

Given a student’s roll number in the following format rollNumber@institute.edu.in, write a program to find the roll number and institute name of the student.
Input:
roll@institute.edu.in
Output:
roll institute

Solution:

a = input()
b = a.split('.')

r = b[0].split('@')[0]
i = b[0].split('@')[1]

print(r, i)

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

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

More Nptel courses: https://progiez.com/nptel-assignment-answers/


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