NPTEL Joy of Computing Using Python Week 9 Programming Assignment 2023

Hello everyone, we came back with Nptel week 9 programming assignment of Joy Of Computing Using Python. In this article we will discuss the answers for week 9 assignment . Please Use these answers as reference, If any doubt arises feel free to comment in the comment section below. Then why Waiting, Come with us, Let us solve the programming assignment. 

Also Read: Joy of computing week 9 quiz answers  

NPTEL Joy of Computing Using Python Week 9 Programming Assignment 2023


The Joy Of Computing Using Python Week 9 Assignment 

Before going to the assignment, let us see the topics briefly which are present in week 9.The topics Present in this week are :  

  • Natural Language Processing - Author Stylometry 
  • Introduction to Networkx
  • Six Degrees of Separation - Meet your Favourites
  • Area Calculation - Don't Measure 

Natural Language Processing 

Author stylometry is a subfield of natural language processing (NLP) that involves the analysis of linguistic patterns in written text to identify the authorship of a document or to attribute multiple documents to the same author. It is based on the idea that each author has a unique writing style that can be quantified and analyzed using statistical and computational methods.

Stylometric analysis involves extracting a range of features from the text, such as word frequencies, sentence length, vocabulary richness, and syntactic patterns. These features are then used to develop a mathematical model that captures the author's writing style. The model can then be used to compare and match documents with similar writing styles to identify potential authorship.

Stylometric analysis has a range of applications, including forensic linguistics, literary studies, and plagiarism detection. It can be used to analyze historical texts, identify anonymous authors, and track the evolution of an author's style over time. However, it is not always reliable, and there are limitations to its accuracy, particularly in cases where authors intentionally modify their writing style to avoid detection.

Introduction to Networkx

NetworkX is a Python library used for the analysis and modeling of complex networks. It provides tools for creating, manipulating, and visualizing graphs and networks, which can be used to represent a wide range of real-world systems, including social networks, transportation networks, and biological systems.

Some of the key features of NetworkX include:

Graph types: NetworkX provides support for a range of graph types, including directed and undirected graphs, weighted and unweighted graphs, and graphs with self-loops and parallel edges.

Graph algorithms: The library includes a range of algorithms for analyzing and manipulating graphs, including shortest path algorithms, centrality measures, community detection algorithms, and random graph generation.

Visualization: NetworkX provides tools for visualizing graphs and networks using Matplotlib, a popular Python plotting library.

Integration with other libraries: NetworkX can be integrated with other Python libraries, such as NumPy and Pandas, to perform advanced data analysis and manipulation.

Extensibility: NetworkX is highly extensible, allowing users to define their own graph types and algorithms.

Overall, NetworkX is a powerful tool for the analysis and modeling of complex networks, providing a range of features and tools that can be used to explore and understand the structure and behavior of these systems.

Six Degrees of Separation - Meet your Favourites 

Six Degrees of Separation is a popular theory that states that any two people in the world are connected by no more than six intermediaries or acquaintances. The theory suggests that every individual is linked to everyone else through a chain of six people, making the world a much smaller place.

Using this theory, we can play a game called "Meet your Favorites," where we can connect ourselves to our favorite celebrities or historical figures through six degrees of separation. Here's an example:

Let's say my favorite actor is Leonardo DiCaprio. Here's how I can connect myself to him:

  1. I studied at the same university as a person who later became a casting director in Hollywood.
  2. This casting director worked on the movie "The Departed," which starred Leonardo DiCaprio.
  3. DiCaprio starred in "The Wolf of Wall Street" with Matthew McConaughey.
  4. McConaughey starred in "Interstellar" with Anne Hathaway.
  5. Hathaway starred in "The Devil Wears Prada" with Emily Blunt.
  6. Blunt starred in "Edge of Tomorrow" with Tom Cruise, who starred in "Interview with the Vampire" with Brad Pitt, who starred in "Once Upon a Time in Hollywood" with Leonardo DiCaprio.
So, I am connected to Leonardo DiCaprio through six degrees of separation. 

Area Calculation - Don't Measure  

Area calculation without measurement is possible using various techniques and methods. Here are a few examples:

Google Maps: Google Maps is a free web mapping service that provides satellite imagery, aerial photography, street maps, and terrain maps. You can use Google Maps to measure the area of a particular location by drawing a polygon around the area you want to measure. Once the polygon is drawn, Google Maps will calculate the area in square meters, square kilometers, square feet, or acres.

Planimeter: A planimeter is a device that can be used to measure the area of a two-dimensional shape without the need for measuring its dimensions. It works by tracing the perimeter of the shape using a pointer, which is connected to a mechanical linkage that calculates the area. Planimeters are commonly used in engineering and surveying applications.

Estimation: In some cases, it is possible to estimate the area of a particular location without using any measurement tools. For example, if you are trying to estimate the area of a rectangular room, you can use the length and width of the room and multiply them to get the area. Similarly, if you are trying to estimate the area of a circular garden, you can use the radius of the garden and use the formula πr² to calculate the area.

Overall, there are various methods available for area calculation without measurement, and the most suitable method will depend on the particular situation and the accuracy required.


Q1.  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:

bananamania
nana

Output:
True

Explanation:

S2 which is nana is in bananamania hence it is a substring of s1.

Example 2:

Input:

aabbcc
abc

output:
False

Explanation:

String s1 does not contain string s2 hence the answer is false. 


Program Code: 

def subStr(s1,s2):
  return(s2 in s1) {codeBox}

Q2.  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} 

Program Code:  

def mergeDic(d1,d2):
  for i in d2.keys():
    if i not in d1.keys():
      d1[i]=d2[i]
  return(d1)  {codeBox}

Q3. Take an integer N as an input, 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

Explanation:
Given integer 122345. Now printing indexes of numbers from left to right.
First number is 1 and its index is 0 therefore
1 0 

Second and third number is 2 and its index is 1,2 therefore
2 1 2

and so on...

Program Code:  

n=int(input())
idp=dict()
for i in str(n):
  idp[i]=[]
  for j in range(len(str(n))):
    if i==str(n)[j]:
      idp[i]+=[j] 
for k in idp:
    print(k,*idp[k],"") {codeBox}

Conclusion: 

I Request everyone to revisit the website on/before to last date for any re-verification of answers.
 
If you have any queries, contact us. I am very thankful to answer you.
 
NOTE: I'm answering these questions to the best of my knowledge.

One Comment Please !

Post a Comment (0)
Previous Post Next Post