Week-2
Quiz AssignmentANS -1) 8
ANS -2) a- x[2] == 487, y[0] == 397, u[2] == 487, w[0] == 357
ANS -3) "aedsoe"
ANS -4) [88,53,12,88,53,97,62]
Programming Assignment
def matched(n):
n=list(n)
C=0
for i in range(len(n)):
if C==-1:
return False
if n[i]=="(":
C=C+1
if n[i]==")":
C=C-1
if C==0:
return True
else:
return False
def rotatelist(arr, n):
l=n%len(arr)
return arr[l:]+arr[:l]
def isP(n):
if n==2:
return True
if n%2==0:
return False
return all(n%x>0 for x in range(3,int(n**0.5)+1,2))
def genP(n):
p = [2]
p.extend([x for x in range(3,n+1,2) if isP(x)])
return p
def primepartition(n):
p = genP(n)
for i in range(0,len(p)):
for j in range(0,len(p)):
if p[i]+p[j]==n:
return True
return False
No comments: