def alternating(l):
if (len(l) > 1):
if l[0] > l[1]:
for i in range(len(l) - 1):
if l[i] == l[i - 1]:
return False
if i % 2 == 0:
if l[i] < l[i + 1]:
return False
if l[0] < l[1]:
for i in range(len(l) - 1):
if i % 2 == 0:
if l[i] > l[i + 1]:
return False
return True

def ascending(lst):
for i in range(0, len(lst) - 1):
if lst[i] > lst[i + 1]:
return False
return True

def matmult(X, Y):
col = len(Y[0])
row = len(X)
result = [[0 for i in range(col)] for j in range(row)]

for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
return result

Can be tested with the following code (Test Cases):-

>>> ascending([])
True

>>> ascending([3,3,4])
True

>>> ascending([7,18,17,19])
False

>>> alternating([])
True

>>> alternating([1,3,2,3,1,5])
True

>>> alternating([3,2,3,1,5])
True

>>> alternating([3,2,2,1,5])
False

>>> alternating([3,2,1,3,5])
False

>>> matmult([[1,2],[3,4]],[[1,0],[0,1]])
[[1,2],[3,4]]

>>> matmult([[1,2,3],[4,5,6]],[[1,4],[2,5],[3,6]])
[[14, 32], [32, 77]]
Categories: NPTEL solution

#### SHAHIM · February 21, 2018 at 5:37 PM

may i know how will be the final exam?
will you update all answers in this sites,
and also can we browse answers while attending exam?

#### Yash Sodha · February 27, 2018 at 4:39 PM

No, you can’t browse the website while attending exam!

#### sashu · February 24, 2018 at 12:58 PM

sir week 3 assignment solution is wrong so please update correct answer

#### Rajat Kanaujia · February 24, 2018 at 5:57 PM

Thanks for providing these solutions for NPTEL assignments .They serve great source for reference while completing our assignments but there is a slight flaw in the code mentioned above for the alternating problem . Though the code is correct in itself but the problem is that it ain’t properly indented ,so I have corrected it on your behalf. I hope it would be helpful .
Once again thank you for your support

def alternating(l):
if(len(l)>1):
if(l[0]>l[1]):
for i in range(len(l)-1):
if(l[i]==l[i-1]):
return False
if(i%2==0):
if(l[i]<l[i+1]):
return False
if(l[0]=l[i+1]):
return False
return True

#### pavan · February 24, 2018 at 6:23 PM

all 10 cases got run time error

#### rg · February 24, 2018 at 6:47 PM

SYNTACTICAL ERROR ARE SHOWN.PLEASE VERIFY THE CODES AGAIN AND THEN UPLOAD. THANK YOU.

#### Rohit Singh · February 25, 2018 at 1:30 AM

Giving error in line 8. “Invalid Syntax”. Please check.

#### krishna · February 25, 2018 at 2:42 AM

thepythom 3rd assignmene is wrong not working

#### manisha · February 27, 2018 at 9:42 AM

ascending([7])
True\n
File “test.py”, line 8\n
if(l[i]<l[i+1]): return="" false="" if(l[0]l[i+1]):\n
^\n
SyntaxError: invalid syntax

#### Ushaif · February 27, 2018 at 2:09 PM

Week 3 program shows error…. Plzz send the correct program….at [email protected]

#### joy · February 27, 2018 at 3:31 PM

I guess there is some error I cant get my code executed plz acknow
ledge

#### BURO BANERJEE · February 27, 2018 at 3:42 PM

YOU HAVE GIVEN SOLLUTION.IT’S FINE BUT THE ANSWERS DO NOT CORRECT.CODE IS NOT RUNNING IN PYTHON SHELL

#### rohhiith · February 27, 2018 at 3:52 PM

Test Case 1 Runtime Error
Input Expected Output Actual Output
ascending([7])
True\n
File “test.py”, line 8\n
if(l[i]<l[i+1]): return="" false="" if(l[0]l[i+1]):\n
^\n
SyntaxError: invalid syntax
it is showing like this. please respond tomorrow is last day for submission.

#### Ankur · February 28, 2018 at 4:25 PM

Please give solutions for week 4 Quiz for python

#### pankaj · February 28, 2018 at 5:33 PM

when I am going to submit assignment week 3 for python programming rutine error is coming.where I am wrong?

#### Yash Sodha · March 1, 2018 at 12:29 PM

Just use raw code .. copying from blog doesn’t work sometimes for some reason.

#### nhi bataunga · February 28, 2018 at 5:55 PM

thanks dude…..helped me get my internals UP

#### Eccentric Child · March 1, 2018 at 6:36 AM

Hey, can you upload answers to the week 4 Quiz and Programming assignment?