NPTEL Data Structure and algorithm using python Week 2 Assignment 2 Solutions 2021 | Swayam




Programming Assignment



def fun(n):
    list1 = []
    for i in range(1,n+1):
        if n%i == 0:
            list1.append(i)
    return(list1)
def check_prime(n):
    return(fun(n) == [1,n])
def primeproduct(n):
    for i in range(1,n+1):
        if n%i == 0:
            if check_prime(i) and check_prime(n//i):
                return(True)
    return(False)
def delchar(s,c):
  if len(c)==1:
    return(s.replace(c,''))
  else:
    return(s)
  
def shuffle(l1,l2):
  t=max(len(l1),len(l2))
  ans=list()
  for i in range(t):
    try:
      ans.append(l1[i])
    except:
      pass
    try:
      ans.append(l2[i])
    except:
      pass
  return(ans)


No comments:

Powered by Blogger.