Question

Based on the following examples of function calls and the respective return values, guess what are...

Based on the following examples of function calls and the respective return values, guess what are the signatures of the functions and then implement them. You are not allowed to use: a) modules, b) slicing, c) aliases, d) the list comprehension syntax (if you don’t know what that is then you can’t use it either).

Function 3: In this function you must both return a value and modify in-place the input
parameter (when needed). The only functions you are allowed to use are range(), len(),
append(), insert(), remove(), pop() and the del keyword.
• Examples:
  return value argument value after return
◦ func3([4,-3,7,-5,1]) → [-3,-5] [4,7,1]
◦ func3([4,-3,7,-5,1], 4) → [-3,-5,1]    [4,7]
◦ func3([4,-3,7,-5,1], 10) → [4,-3,7,-5,1] [ ]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def func3(numbers,separator=0):
    '''
    returns a list of numbers from the list numbers less than separator
    default value for separator is 0
    the list numbers is modified to contain numbers greatr than or equal to separaor
    '''
    less=[]
    indice=[]
    for i in range(len(numbers)):
        if numbers[i]<separator:
            indice.append(i)

    j=0
    for i in indice:
        less.append(numbers[i-j])
        del numbers[i-j]
        j=j+1

    return less
Add a comment
Know the answer?
Add Answer to:
Based on the following examples of function calls and the respective return values, guess what are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone help me solve this? I need to return a single list. Not 2 separate...

    Can someone help me solve this? I need to return a single list. Not 2 separate lists. I also need to modify a list of numbers. Function 3: In this function you must both return a value and modify in-place the input parameter (when needed). The only functions you are allowed to use are range(), len(), append(), insert(), remove(), pop() and the del keyword. • Examples: return value argument value after return ◦ func3([4,-3,7,-5,1]) → [-3,-5] [4,7,1] ◦ func3([4,-3,7,-5,1], 4)...

  • Can some help me solve these? I am confused on where to start. I know in...

    Can some help me solve these? I am confused on where to start. I know in some cases, since there are no arguments, I can use *. Function 3: In this function you must both return a value and modify in-place the input parameter (when needed). The only functions you are allowed to use are range(), len(), append(), insert(), remove(), pop() and the del keyword. • Examples: return value argument value after return ◦ func3([4,-3,7,-5,1]) → [-3,-5] [4,7,1] ◦ func3([4,-3,7,-5,1],...

  • Python code: using only len(), range(), append(), and del keyword when needed as the directions state?...

    Python code: using only len(), range(), append(), and del keyword when needed as the directions state? No list comprehension, slicing, or importing modules. Please and thank you. def diagonal_matrix(mat) Converts a square matrix mat into a lower diagonal matrix https://en.wikipedia.org/wiki/Triangular_matrix After the conversion the values on the diagonal will be the sum of the deleted elements in the respective row Return value is None. Variable mat is directly modi ed in memory mat is a nested list (e.g. [[1,2,3], [4,5,6],...

  • Can someone solve these for me using only len(), range(), append(), and del keyword when needed...

    Can someone solve these for me using only len(), range(), append(), and del keyword when needed as the directions state? No list comprehension, slicing, or importing modules. No chr or index(i) functions. def reduce_matrix(mat) • Reduces the size of matrix mat in half, in both dimensions, by merging adjacent elements • The new values of the matrix are the average of the respective merged elements • Return value is None. Variable mat is directly modified in memory • mat is...

  • Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that...

    Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that occurs as consecutive characters (not just letters, but any characters) in s. so longestSubpalindrome("ab-4-be!!!") returns "b-4-b".If there is a tie, return the lexicographically larger value -- in Python, a string s1 is lexicographically greater than a string s2 if (s1 > s2). So: longestSubpalindrome("abcbce") returns "cbc", since ("cbc" > "bcb"). Note that unlike the previous functions, this function is case-sensitive (so "A" is not...

  • Fit to page ID Page view A Re - + of the cropped tile, width (int)...

    Fit to page ID Page view A Re - + of the cropped tile, width (int) is the width of the cropped tile Retur ed image that is a 3D list of int Example crop ([ LLU ,1, ,2,2), (3,3,3]], [(4,4,4], [5,5,5),(6,6,6]], [[7,7,7], [8,8,8], [9,9,9]] ), (0,0), 1, 2) [[[1,1,1], [2,2,2]]] color2gray(image) Description: It takes a color image (3D list) and returns a new grayscale image (2D list) where each pixel will take the average value of the three color...

  • Python3 please use while loop to solve this question,specific information is on the graph Question 2...

    Python3 please use while loop to solve this question,specific information is on the graph Question 2 - 15 marks Write the function read_file_center50 (filename). The function returns a list of 50 strings that are at the center of the file. A file has n lines, then is the center. A list of length 50 is returned, where the first line is 25 and the last line is 2 + 25. If the file has n < 50 lines, then only...

  • Python3, write a program, specific information is in the graphs, I got 7 marks out of...

    Python3, write a program, specific information is in the graphs, I got 7 marks out of 10, you may change my codes to let it gives correct output,restrications are also on the graph, for loop, in key word, enumerate,zip,slices, with key word can't be used. All the information is on the graph, is_shakespeare_play(line) may be a function given that can check whether is Shakespeare play Question 2- 10 marks Write the function keep titles short (filename, max charactars) which takes...

  • on.ca i.cmd med to u nunaown C eSA COwPA 20 or 2. Write a function that...

    on.ca i.cmd med to u nunaown C eSA COwPA 20 or 2. Write a function that takes a single list of characters as argument and returns a new list of integers as a return value. The list returned must contain the ASCII codes of every uppercase character in the original list in the reverse order from the order they appeared in the original list. You are not permitted to use negative indexing (i.e., the numbers you write in the square...

  • PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the...

    PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the map referred to is pictured in the screenshot. Need help with these 4 tasks: Function 4: def is_map(map) : given a map (see screenshot), does it meet the following criteria? 1) it is a list of lists of values of type int; 2) it has at least one row and one column; 3) it’s rectangular (all sub-lists are same length); 4) only non-negative ints...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT