NPTEL » The Joy of Computing using Python
Please scroll down for latest Programs 👇
Week 2 - Programming Assignment 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 | 1 | 1\n
| Passed after ignoring Presentation Error |
Test Case 2 | 2 | 1 | 1\n
| Passed after ignoring Presentation Error |
Test Case 3 | 10 | 25 | 25\n
| Passed after ignoring Presentation Error |
Week 2 - Programming Assignment 2
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 0 | Neon Number | Neon Number\n
| Passed after ignoring Presentation Error |
Test Case 2 | 1 | Neon Number | Neon Number\n
| Passed after ignoring Presentation Error |
Test Case 3 | 2 | Not Neon Number | Not Neon Number\n
| Passed after ignoring Presentation Error |
Week 2 - Programming Assignment 3
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | hello | 2 | 2\n
| Passed after ignoring Presentation Error |
Test Case 2 | PYTHON | 1 | 1\n
| Passed after ignoring Presentation Error |
Test Case 3 | OpenAI 123 | 4 | 4\n
| Passed after ignoring Presentation Error |
Week 6 Programming Assignment : 1
Problem: Robot Arithmetic Module – Engineering Constraint
At RoboCore Labs, engineers are developing an embedded system for a low-power educational robot.
Due to hardware limitations, the robot’s control unit cannot use the built-in multiplication operation.
As a member of the firmware team, your task is to implement a function that computes the product of two positive integers without using the *
operator.
Requirements:
Function Name:
multiply
Parameters:
a
(positive integer)b
(positive integer)
Constraints:
You may only use the
+
(addition) and-
(subtraction) operators.The
*
(multiplication) operator is strictly forbidden.
Return Value:
The function should return the product of
a
andb
.
Implementation:
The solution must be implemented using recursion.
Note:
Do not read input from the user.
Do not print output to the console.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
3 | 6 | 6\n
| Passed after ignoring Presentation Error |
Test Case 2 | 5
4 | 20 | 20\n
| Passed after ignoring Presentation Error |
Test Case 3 | 10
17 | 170 | 170\n
| Passed after ignoring Presentation Error |
Test Case 4 | 23
4 | 92 | 92\n
| Passed after ignoring Presentation Error |
Test Case 5 | 100
1 | 100 | 100\n
| Passed after ignoring Presentation Error |
Week 6 Programming Assignment : 2
Problem: Searching Patient Records in a Health Analytics System
The hospital network MedNexus maintains a centralized database of patient record IDs.
These IDs are stored in sorted order to enable fast lookups.
You are part of the software development team tasked with optimizing the search functionality.
Since the system follows a recursive design pattern, you must implement a recursive version of the search algorithm to determine whether a given patient ID exists in the records.
Requirements
Function Name:
search
Parameters:
L
→ A sorted list of integers (patient record IDs).k
→ An integer representing the ID to search for.
Return Value:
Return
True
ifk
is present inL
.Return
False
ifk
is not present.
Constraints:
Must use recursion.
No need to accept input from the user.
No need to print output to the console. Only the function definition is required.
Example
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | search([1, 2, 3, 4], 2) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 2 | search([10, 20, 30, 40, 50], 15) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 3 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], 31) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 4 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], 50) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 5 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], -100) | True | True\n
| Passed after ignoring Presentation Error |
Test Case 6 | search([-100, -10, 1, 10, 20, 30, 30, 40, 50], -200) | False | False\n
| Passed after ignoring Presentation Error |
Test Case 7 | search([10], 10) | True | True\n
| Passed after ignoring Presentation Error |
Week 6 : Programming Assignment 3
Problem: Signal Propagation in Network Simulation
At NeuroLink Systems, researchers are developing a simulation to analyze how signals propagate in a neural network grid.
The network is represented as a square matrix
A
, where each entry represents the connection strength between neurons.To study influence over multiple steps, the team must compute the matrix raised to a power
m
.Each matrix multiplication represents one time step of propagation.
Your task is to implement a recursive function to compute the power of a matrix.
Requirements
Function Name:
power
Parameters:
A
: A square matrix (2D list of integers or floats).m
: A positive integer (exponent).
Return Value:
The matrix
A^m
, computed recursively.
Constraints:
Must use recursion.
No user input or console printing — only function definition required.
Example
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
3
1,2,3
4,5,6
7,8,9 | 468,576,684\n
1062,1305,1548\n
1656,2034,2412 | 468,576,684\n
1062,1305,1548\n
1656,2034,2412\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3
2
1,2,3
4,5,6
7,8,10 | 30,36,45\n
66,81,102\n
109,134,169 | 30,36,45\n
66,81,102\n
109,134,169\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3
4
1,0,0
0,1,0
0,0,1 | 1,0,0\n
0,1,0\n
0,0,1 | 1,0,0\n
0,1,0\n
0,0,1\n
| Passed after ignoring Presentation Error |
Test Case 4 | 4
3
1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16 | 3140,3560,3980,4400\n
7268,8232,9196,10160\n
11396,12904,14412,15920\n
15524,17576,19628,21680 | 3140,3560,3980,4400\n
7268,8232,9196,10160\n
11396,12904,14412,15920\n
15524,17576,19628,21680\n
| Passed after ignoring Presentation Error |
Week 7 : Programming Assignment 1
Problem 1: Image Noise Isolation in Data Analysis
At a medical research lab, image preprocessing involves working with square matrices that represent pixel intensity grids extracted from medical images.
Sometimes, due to faulty sensor data, certain rows and columns must be eliminated to isolate sub-regions of the matrix.
Your task is to implement a function that removes a specified row and column from a square matrix to produce a minor matrix.
Requirements
Function Name:
minor_matrix
Parameters:
M
: A square matrix (list of lists).i
: Index of the row to remove (0-based).j
: Index of the column to remove (0-based).
Return Value:
A new matrix with the
i
-th row andj
-th column removed.
Constraints:
The matrix
M
is always square (n × n
).M
has at least 3 rows and columns.Indexing is zero-based.
No input/output required — just define the function.
Example
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
1,2,3
4,5,6
7,8,9
0
1 | 4,6\n
7,9 | 4,6\n
7,9\n
| Passed after ignoring Presentation Error |
Test Case 2 | 3
1,2,3
4,5,6
7,8,9
2
0 | 2,3\n
5,6 | 2,3\n
5,6\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3
1,2,3
1,2,3
1,2,3
0
0 | 2,3\n
2,3 | 2,3\n
2,3\n
| Passed after ignoring Presentation Error |
Test Case 4 | 4
1,2,3,1
2,10,20,4
43,19,98,100
19,48,49,1
2
3 | 1,2,3\n
2,10,20\n
19,48,49 | 1,2,3\n
2,10,20\n
19,48,49\n
| Passed after ignoring Presentation Error |
Week 7 : Programming Assignment 2
Problem: Generating the IPL Points Table
You are part of the analytics team at the Indian Premier League (IPL) headquarters.
This year, a special edition of the tournament was organized as a round-robin event where each team played exactly one match against every other team. There were no ties — every match resulted in a clear winner and loser.
Eight teams participated in this format:
CSK, DC, KKR, MI, PK, RR, RCB, SH
The tournament officials recorded match outcomes in a specific format. For each team (in a fixed order), they listed the names of the teams it defeated. The lines follow this order:
CSK, DC, KKR, MI, PK, RR, RCB, SH
Example:
indicates that CSK won against MI, DC, and PK, and lost its remaining matches.
If a line only contains the team’s name (e.g., RCB
), it means that team lost all its matches.
Your Task
(a) Process the 8 lines of input and compute the total number of matches won by each team.
(b) Prepare the final IPL points table in descending order of number of wins.
(c) If two or more teams have the same number of wins, sort them in alphabetical order.
(d) Print each entry in the format:
with no spaces and one entry per line.
Constraints
Input always follows the described format.
Every team plays exactly 7 matches.
No drawn or tied games.
Example Input
Example Output
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | CSK,DC,KKR,MI,PK,RR,RCB,SH
DC,KKR,MI,PK,RR,RCB,SH
KKR,MI,PK,RR,RCB,SH
MI,PK,RR,RCB,SH
PK,RR,RCB,SH
RR,RCB,SH
RCB,SH
SH | CSK:7\n
DC:6\n
KKR:5\n
MI:4\n
PK:3\n
RR:2\n
RCB:1\n
SH:0 | CSK:7\n
DC:6\n
KKR:5\n
MI:4\n
PK:3\n
RR:2\n
RCB:1\n
SH:0\n
| Passed after ignoring Presentation Error |
Test Case 2 | CSK,DC,MI,PK
DC,RR,RCB,SH
KKR,CSK,DC,RR,MI
MI,DC,RCB,RR
PK,DC,KKR,MI,RCB
RR,CSK,PK,SH
RCB,CSK,KKR,RR
SH,CSK,KKR,MI,PK,RCB | SH:5\n
KKR:4\n
PK:4\n
CSK:3\n
DC:3\n
MI:3\n
RCB:3\n
RR:3 | SH:5\n
KKR:4\n
PK:4\n
CSK:3\n
DC:3\n
MI:3\n
RCB:3\n
RR:3\n
| Passed after ignoring Presentation Error |
Test Case 3 | CSK,RCB,MI,KKR
DC,CSK,KKR,MI,SH
KKR,PK,RR,RCB,SH
MI,KKR,PK,RR,SH,RCB
PK,CSK,DC,RCB
RR,CSK,DC,PK,SH
RCB,DC,RR
SH,CSK,PK,RCB | MI:5\n
DC:4\n
KKR:4\n
RR:4\n
CSK:3\n
PK:3\n
SH:3\n
RCB:2 | MI:5\n
DC:4\n
KKR:4\n
RR:4\n
CSK:3\n
PK:3\n
SH:3\n
RCB:2\n
| Passed after ignoring Presentation Error |
Test Case 4 | CSK
DC,CSK,KKR,MI,PK,RR,RCB,SH
KKR,CSK,MI,PK
MI,CSK,PK,RR,SH,RCB
PK,CSK,RCB,SH
RR,CSK,KKR,PK
RCB,CSK,KKR,RR,SH
SH,CSK,KKR,RR | DC:7\n
MI:5\n
RCB:4\n
KKR:3\n
PK:3\n
RR:3\n
SH:3\n
CSK:0 | DC:7\n
MI:5\n
RCB:4\n
KKR:3\n
PK:3\n
RR:3\n
SH:3\n
CSK:0\n
| Passed after ignoring Presentation Error |
Test Case 5 | CSK,SH,RCB
DC,CSK,SH
KKR,CSK,DC
MI,CSK,DC,KKR
PK,CSK,DC,KKR,MI
RR,CSK,DC,KKR,MI,PK
RCB,DC,KKR,MI,PK,RR
SH,KKR,MI,PK,RR,RCB | RCB:5\n
RR:5\n
SH:5\n
PK:4\n
MI:3\n
CSK:2\n
DC:2\n
KKR:2 | RCB:5\n
RR:5\n
SH:5\n
PK:4\n
MI:3\n
CSK:2\n
DC:2\n
KKR:2\n
| Passed after ignoring Presentation Error |
Week 7 : Programming Assignment 3
Problem Statement: Symmetric Double Pyramid Pattern
Objective:
Write a program to print a symmetric star pattern based on a given integer input n
.
Input:
A single integer
n
(1 ≤ n ≤ 100), representing the number of rows in the upper half of the pattern.
Output:
Print a pattern consisting of
2n - 1
rows.Each row should contain stars and spaces arranged symmetrically according to the value of
n
.
Example:
Input:
Output:
* * ** ** *** *** ******** *** *** ** ** * *
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 | * *\n
** **\n
*** ***\n
********\n
*** ***\n
** **\n
* * | * *\n
** **\n
*** ***\n
********\n
*** ***\n
** **\n
* *\n
| Passed after ignoring Presentation Error |
Test Case 2 | 2 | * *\n
****\n
* * | * *\n
****\n
* *\n
| Passed after ignoring Presentation Error |
Test Case 3 | 3 | * *\n
** **\n
******\n
** **\n
* * | * *\n
** **\n
******\n
** **\n
* *\n
| Passed after ignoring Presentation Error |
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.