Programming Data Structures And algorithms using Python Week 3 Solutions 2024

ABOUT THE COURSE :

Programming Data Structures And algorithms using Python Week 3 Solutions

Disclaimer: The answers to these questions are provided for educational and informational purposes only. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.

This course is an introduction to programming and problem solving in Python. It does not assume any prior knowledge of programming. Using some motivating examples, the course quickly builds up basic concepts such as conditionals, loops, functions, lists, strings and tuples. It goes on to cover searching and sorting algorithms, dynamic programming and backtracking, as well as topics such as exception handling and using files. As far as data structures are concerned, the course covers Python dictionaries as well as classes and objects for defining user defined datatypes such as linked lists and binary search trees.

Summary
Course Type Elective
Duration 8 weeks
Category
  • Computer Science and Engineering
  • Artificial Intelligence
  • Data Science
  • Foundations of Computing
  • Programming
Start Date 22 Jan 2024
End Date 15 Mar 2024
Exam Registration Ends 16 Feb 2024
Exam Date 24 Mar 2024 IST

Assignment Solutions : Week 3 Programming Assignment

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 10 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. Define a Python function remdup(l) that takes a nonempty list of integers l and removes all duplicates in l, keeping only the first occurrence of each number. For instance:

    >>> remdup([3,1,3,5])
    [3, 1, 5]
    
    >>> remdup([7,3,-1,-5])
    [7, 3, -1, -5]
    
    >>> remdup([3,5,7,5,3,7,10])
    [3, 5, 7, 10]
    
  2. Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

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

    >>> sumsquare([1,3,5])
    [35, 0]
    
    >>> sumsquare([2,4,6])
    [0, 56]
    
    >>> sumsquare([-1,-2,3,7])
    [59, 4]
    
  3. A two dimensional matrix can be represented in Python row-wise, as a list of lists: each inner list represents one row of the matrix. For instance, the matrix

    1  2  3  4
    5  6  7  8
    

    would be represented as [[1, 2, 3, 4], [5, 6, 7, 8]].

    The transpose of a matrix converts each row into a column. The transpose of the matrix above is:

    1  5
    2  6
    3  7
    4  8
    

    which would be represented as [[1, 5], [2, 6], [3, 7], [4, 8]].

    Write a Python function transpose(m) that takes as input a two dimensional matrix m and returns the transpose of m. The argument m should remain undisturbed by the function.

    Here are some examples to show how your function should work. You may assume that the input to the function is always a non-empty matrix.

    >>> transpose([[1,2,3],[4,5,6]])
    [[1, 4], [2, 5], [3, 6]]
    
    >>> transpose([[1],[2],[3]])
    [[1, 2, 3]]
    
    >>> transpose([[3]])
    [[3]]
    
    
Solution : Copy & Paste
def remdup(l):
  L=[]
  for ips in l:
    if ips not in L:
      L.append(ips)
  return(L)

def sumsquare(l):
  odd_sum=0
  even_sum=0
  for ats in l:
    if ats%2!=0:
      odd_sum+=ats*ats
    else:
      even_sum+=ats*ats
  return([odd_sum,even_sum])

def transpose(m):
  ans=list()
  for ind in range(len(m[0])):
    a=[]
    for j in range(len(m)):
      a.append(m[j][ind])
    ans.append(a)
  return(ans)

CRITERIA TO GET A CERTIFICATE :
  1. Average assignment score = 25% of average of best 6 assignments out of the total 8 assignments given in the course. (All assignments in a particular week will be counted towards final scoring - quizzes and programming assignments).
  2. Exam score = 75% of the proctored certification exam score out of 100
  3. Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met,you will not get the certificate even if the Final score >= 40/100.

Join With Us On :

Join Now


Previous Year Questions Now to Boost Your Exam Performance

LOADS OF LOGIC