Hey Folks, I hope all are doing good. In this article, Answers for the NPTEL Joy Of Computing Using Python Week 9 Programming Assignment 2025 will be shared. The answers for the Nptel Week 8 Programming Assignment of Python are given below.Â
Also Read:Â NPTEL Joy Of Computing Using Python Week 8 Programming Assignment 2025
Upcoming answers are provided in Telegram faster
Join us on Telegram 👉 CLICK HERE Â
NPTEL Joy Of Computing Using Python Week 9 Programming Assignment 2025
In this article the following topics are discussed:Â
- Natural language Processing - Author Stylometry
- Introduction to networkx
- Six Degrees of Separation
- Area of Calculation - Don't Measure
Last Date: 27-03-2025
Q1. We represent scores of batsmen across a sequence of matches in a two-level dictionary as follows:
{'match1’: {'player1':57, 'player2':38}, 'match2’: {'player3':9, 'player1':42}, 'match3’: {'player2':41, 'player4':63, 'player3':91}
Each match is identified by a string, as is each player. The scores are all integers. The names associated with the matches are not fixed (here they are 'match1', 'match2', 'match3'), nor are the names of the players. A player need not have a score recorded in all matches.
Define a Python function orangecap(d) that reads a dictionary d of this form and identifies the player with the highest total score. Your function should return a pair (playername, topscore) where playername is a string, the name of the player with the highest score, and topscore is an integer, the total score of playername.
The input will be such that there are never any ties for highest total score.
For Example :
InputÂ
{'match1’: {'player1':57, 'player2':38}, 'match2':{'player3':9, 'player1':42}, 'match3':{'player2':41, 'player4':63, 'player3':91}}
Output
('player3', 100)
Input
{'test1':{'Pant':84, 'Kohli':120}, 'test2':{'Pant':59, 'Gill':42}}
Output
('Pant', 143)
Program Code:Â
def orangecap(d):  player_scores={}  for match in d.values():   for player, score in match.items():    player_scores[player] = player_scores.get(player, 0) + score  Â  top_player = max(player_scores, key=player_scores.get)  Â  return (top_player, player_scores[top_player]) {codeBox}
Q2. A positive integer m can be expressed as the sum of three squares if it is of the form p + q + r where p, q, r ≥ 0, and p, q, r are all perfect squares. For instance, 2 can be written as 0+1+1 but 7 cannot be expressed as the sum of three squares. The first numbers that cannot be expressed as the sum of three squares are 7, 15, 23, 28, 31, 39, 47, 55, 60, 63, 71, …(see Legendre's three-square theorem).
    Write a Python function threesquares(m) that takes an integer m as a parameter and returns True if m can be expressed as the sum of three squares and False otherwise.  (If m is not positive, your function should return False.)
Program Code:Â
import mathdef threesquares(m):Â Â if m <= 0:Â Â Â Â print(False)Â ÂÂ Â while m % 4 == 0:Â Â Â Â m //= 4Â ÂÂ Â return m % 8!= 7 {codeBox}
Q3. A list of numbers is said to be a hill if it consists of an ascending sequence followed by a descending sequence, where each of the sequences is of length at least two. Similarly, a list of numbers is said to be a valley if it consists of an descending sequence followed by an ascending sequence. You can assume that consecutive numbers in the input sequence are always different from each other.
Write a Python function hillvalley(l) that takes a list l of integers and returns True if it is a hill or a valley, and False otherwise.
Here are some examples to show how your function should work.
>>> hillvalley([1,2,3,5,4])
True
>>> hillvalley([1,2,3,4,5])
False
>>> hillvalley([5,4,1,2,3])
True
>>> hillvalley([5,4,3,2,1])
False
   Â
Program Code:Â
def hillvalley(l):  if len(l) < 4: Â    return False  i = 1  while i < len(l) and l[i] > l[i - 1]: Â    i += 1  if i < 2 or i == len(l): Â    i = 1 Â    while i < len(l) and l[i] < l[i - 1]: Â      i += 1    if i < 2 or i == len(l): Â      return False    while i < len(l) and l[i] > l[i - 1]: Â      i += 1    return i == len(l) Â Â  while i < len(l) and l[i] < l[i - 1]:    i += 1  return i == len(l) {codeBox}
 Â