Programming, Data Structures And Algorithms Using Python - Week 2 Programming Assignment Jun-Dec, 2021

NPTEL PROGRAMMING ASSIGNMENTS

 

Programming, Data Structures And Algorithms Using Python


Week 2 Programming Assignment

Due on 2021-08-19, 23:59 IST
Write three Python functions as specified below. Paste the text for all three functions together into the submission window. Your function will be called automatically with various inputs and should return values as specified. Do not write commands to read any input or print any output.
  • You may define additional auxiliary functions as needed.
  • In all cases you may assume that the value passed to the function is of the expected type, so your function does not have to check for malformed inputs.
  • For each function, there are normally some public test cases and some (hidden) private test cases.
  • "Compile and run" will evaluate your submission against the public test cases.
  • "Submit" will evaluate your submission against the hidden private test cases. There are 12 private test cases, with equal weightage. You will get feedback about which private test cases pass or fail, though you cannot see the actual test cases.
  • Ignore warnings about "Presentation errors".

  1. A positive integer m is a prime product if it can be written as p×q, where p and q are both primes. .

    Write a Python function primeproduct(m) that takes an integer m as input and returns True if m is a prime product and False otherwise. (If m is not positive, your function should return False.)

    Here are some examples of how your function should work.



         >>> primeproduct(6)
         True
         >>> primeproduct(188)
         False
         >>> primeproduct(202)
         True



  2. Write a function delchar(s,c) that takes as input strings s and c, where c has length 1 (i.e., a single character), and returns the string obtained by deleting all occurrences of c in s. If c has length other than 1, the function should return s

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



         >>> delchar("banana","b")
         'anana'
         >>> delchar("banana","a")
         'bnn'
         >>> delchar("banana","n")
         'baaa'
         >>> delchar("banana","an")
         'banana'



  3. Write a function shuffle(l1,l2) that takes as input two lists, 11 and l2, and returns a list consisting of the first elment in l1, then the first element in l2, then the second element in l2, then the second element in l2, and so on. If the two lists are not of equal length, the remaining elements of the longer list are appended at the end of the shuffled output.

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

         >>> shuffle([0,2,4],[1,3,5])
         [0, 1, 2, 3, 4, 5]
         >>> shuffle([0,2,4],[1])
         [0, 1, 2, 4]
         >>> shuffle([0],[1,3,5])
         [0, 1, 3, 5]



     

     


Post a Comment (0)
Previous Post Next Post