9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
([Link] ([Link]
dsmari2003@[Link]
NPTEL ([Link] » Programming, Data Structures and Algorithms using
Python (course)
If already Week 3 Programming Assignment
registered, click
Due on 2025-08-14, 23:59 IST
to check your
payment status
Course
outline
About NPTEL
()
How does an
NPTEL online
course work?
()
Week 1 :
Introduction ()
Week 1 Quiz ()
Week 2:
Basics of
Python ()
Week 2 Quiz ()
[Link] 1/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
Week 2
Programming
Assignment ()
Week 3: Lists,
inductive
function
definitions,
sorting ()
Week 3
Programming
Assignment ()
Week 3
Programming
Assignment
(/noc25_cs89/p
rogassignment
?name=213)
Week 4:
Sorting,
Tuples,
Dictionaries,
Passing
Functions,
List
Comprehensi
on ()
Week 4 Quiz ()
Week 4
Programming
Assignment ()
Week 5:
Exception
handling,
input/output,
file handling,
string
processing ()
Week 5
Programming
Assignment ()
[Link] 2/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
Write three Python functions as specified below. Paste the text for all three
Week 6:
Backtracking,
functions together into the submission window. Your function will be called
scope, data automatically with various inputs and should return values as specified. Do not
structures; write commands to read any input or print any output.
stacks, You may define additional auxiliary functions as needed.
queues and In all cases you may assume that the value passed to the function is of the
heaps () expected type, so your function does not have to check for malformed inputs.
For each function, there are normally some public test cases and some
Week 6 Quiz () (hidden) private test cases.
"Compile and run" will evaluate your submission against the public test cases.
Week 7: "Submit" will evaluate your submission against the hidden private test cases.
Classes, There are 12 private test cases, with equal weightage. You will get feedback
objects and about which private test cases pass or fail, though you cannot see the actual
user defined test cases.
datatypes () Ignore warnings about "Presentation errors".
Week 7 Quiz ()
1. Write a function expanding(l) that takes as input a list of integer l and
Week 8: returns True if the absolute difference between each adjacent pair of
Dynamic elements strictly increases.
programming,
wrap-up () Here are some examples of how your function should work.
Week 8 >>> expanding([1,3,7,2,9])
Programming True
Assignment ()
Explanation: Differences between adjacent elements are 3-1 = 2, 7-3
Text = 4, 7-2 = 5, 9-2 = 7.
Transcripts ()
>>> expanding([1,3,7,2,-3])
Books () False
Download Explanation: Differences between adjacent elements are 3-1 = 2, 7-3
Videos () = 4, 7-2 = 5, 2-(-3) = 5, so not strictly increasing.
Problem >>> expanding([1,3,7,10])
Solving False
Session - July
2025 () Explanation: Differences between adjacent elements are 3-1 = 2, 7-3
= 4, 10-7 = 3, so not increasing.
2. Write a Python function sumsquare(l) that takes a nonempty list of
integers and returns a list [odd,even], where odd is the sum of
squares all the odd numbers in l and even is the sum of squares of all
the even numbers in l.
Here are some examples to show how your function should work.
>>> sumsquare([1,3,5])
[35, 0]
[Link] 3/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
>>> sumsquare([2,4,6])
[0, 56]
>>> sumsquare([-1,-2,3,7])
[59, 4]
3. A two dimensional matrix can be represented in Python row-wise, as a
list of lists: each inner list represents one row of the matrix. For
instance, the matrix
1 2 3 4
5 6 7 8
would be represented as [[1, 2, 3, 4], [5, 6, 7, 8]].
The transpose of a matrix converts each row into a column. The
transpose of the matrix above is:
1 5
2 6
3 7
4 8
which would be represented as [[1, 5], [2, 6], [3, 7], [4,
8]].
Write a Python function transpose(m) that takes as input a two
dimensional matrix m and returns the transpose of m. The argument m
should remain undisturbed by the function.
Here are some examples to show how your function should work. You
may assume that the input to the function is always a non-empty matrix.
>>> transpose([[1,2,3],[4,5,6]])
[[1, 4], [2, 5], [3, 6]]
>>> transpose([[1],[2],[3]])
[[1, 2, 3]]
>>> transpose([[3]])
[[3]]
[Link] 4/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
Private
Test
Expected Actual
cases Input Status
Output Output
used for
evaluation
Test Case
expanding([11,35,77,21,98]) True True\n Passed
1
[Link] 5/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
Test Case
expanding([11,38,79,25,-36]) True True\n Passed
2
Test Case
expanding([-1,2,-3,4,-5,6,-7,8,-9,10,-11,12]) True True\n Passed
3
Test Case
expanding([-1,2,-3,4,-5,6,-7,8,-9,10,-11,-32]) False\n Passed
4 False
Test Case [35, [35,
sumsquare([1,-2,-3,4,5,6]) Passed
5 56] 56]\n
Test Case [455,
sumsquare([1,3,5,7,9,11,13]) [455, Passed
6 0]\n
0]
Test Case [0, [0,
sumsquare([0,2,4,6,8,10,12]) Passed
7 364] 364]\n
Test Case [20, [20,
sumsquare([0,1,-1,0,2,-2,3,-3]) Passed
8 8] 8]\n
[[1,
4,
7], [[1, 4,
[2, 7], [2,
Test Case
transpose([[1,2,3],[4,5,6],[7,8,9]]) 5, 5, 8], Passed
9
8], [3, 6,
[3, 9]]\n
6,
9]]
[[1],
[[1],
Test Case [2],
transpose([[1,2,3,4]]) [2], Passed
10 [3],
[3],
[4]]\n
[4]]
[[1, [[1, 2,
Test Case
transpose([[1],[2],[3],[4]]) 2, 3, 3, Passed
11
4]] 4]]\n
[Link] 6/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
[[1,
0,
0], [[1, 0,
[0, 0], [0,
Test Case
transpose([[1,0,0],[0,1,0],[0,0,1]]) 1, 1, 0], Passed
12
0], [0, 0,
[0, 1]]\n
0,
1]]
The due date for submitting this assignment has passed.
12 out of 12 tests passed.
You scored 100.0/100.
Assignment submitted on 2025-08-13, 23:39 IST
Your last recorded submission was :
1 def expanding(l):
2 # Calculate the list of absolute differences
3 diffs = [abs(l[i+1] - l[i]) for i in range(len(l) - 1)]
4
5 # Check if the differences are strictly increasing
6 for i in range(len(diffs) - 1):
7 if diffs[i] >= diffs[i + 1]:
8 return False
9 return True
10 def sumsquare(l):
11 odd = 0
12 even = 0
13 for num in l:
14 if num % 2 == 0:
15 even += num ** 2
16 else:
17 odd += num ** 2
18 return [odd, even]
19 def transpose(m):
20 return [[row[i] for row in m] for i in range(len(m[0]))]
21
22 ###################
23
24 import ast
25
26 def parse(inp):
27 inp = ast.literal_eval(inp)
28 return (inp)
29
30 fncall = input()
31 lparen = [Link]("(")
32 rparen = [Link](")")
33 fname = fncall[:lparen]
34 farg = fncall[lparen+1:rparen]
35
36 if fname == "expanding":
37 arg = parse(farg)
38 print(expanding(arg))
39
40 if fname == "sumsquare":
41 arg = parse(farg)
42 print(sumsquare(arg))
43
44 if fname == "transpose":
45 arg = parse(farg)
46 savearg = arg
47 ans = transpose(arg)
[Link] 7/8
9/12/25, 2:11 PM Programming, Data Structures and Algorithms using Python - Course
48 if savearg == arg:
49 print(ans)
50 else:
51 print("Side effect")
Sample solutions (Provided by instructor)
[Link] 8/8