# Programming Data Structures And Algorithms Using Python Coding Assignment 2

Programming Data Structures And Algorithms Using Python Coding Assignment 2 Answers:- Hello students in this article we are going to share NPTEL Programming Data Structures And Algorithms Using Python assignment week 2 answers. All the Answers provided below to help the students as a reference, You must submit your assignment at your own knowledge.

Below you can find Programming Data Structures And Algorithms Using Python Coding Assignment 2 Answers

### Programming Data Structures And Algorithms Using Python Coding Assignment 2 Answers 2022:-

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

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 has matched brackets and False if it does not.

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

Code:-

``````def intreverse(n):
ans = 0
while n > 0:
(d,n) = (n%10,n//10)
ans = 10*ans + d
return(ans)

def matched(s):
nested = 0
for i in range(0,len(s)):
if s[i] == "(":
nested = nested+1
elif s[i] == ")":
nested = nested-1
if nested < 0:
return(False)
return(nested == 0)

def factors(n):
factorlist = []
for i in range(1,n+1):
if n%i == 0:
factorlist = factorlist + [i]
return(factorlist)

def isprime(n):
return(factors(n) == [1,n])

def sumprimes(l):
sum = 0
for i in range(0,len(l)):
if isprime(l[i]):
sum = sum+l[i]
return(sum)``````