Programming, Data Structures And Algorithms Using Python - Week 2 Programming Assignment Jul-Dec 2022

  NPTEL PROGRAMMING ASSIGNMENTS

Programming, Data Structures And Algorithms Using Python

Week 2 Programming Assignment

Due on 2022-08-11, 23:59 IST

1. Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n.

Here are some examples of how your function should work.



Function:

intreverse(125)

Expected Output:
521


Function:

intreverse(25444)

Expected Output:
44452

Function:

intreverse(5)

Expected Output:
5


2. Write a function matched(s) that takes as input a string s and checks if the brackets "(" and ")" in s are matched: that is, every "(" has a matching ")" after it and every ")" has a matching "(" before it. Your function should ignore all other symbols that appear in s. Your function should return True if s as matched brackets and False if it does not.

Here are some examples to show how your function should work.



Function:
matched("zb%78")

Expected Output:

True


Function:
matched("(b(78")

Expected Output:

False



Function:
matched("((b)7kl448)")

Expected Output:

True





3. Write a function sumprime(l) that takes as input a list of integers l and retuns the sum of all the prime numbers in l.

Here are some examples to show how your function should work.



Function:
sumprimes([3, 3, 1, 13])

Expected Output:

19


Function:
sumprimes([1, 2, 5, 8])

Expected Output:

7


Function:
sumprimes([-3, 1, 6])

Expected Output:

0


 

 


Post a Comment (0)
Previous Post Next Post