Question: 1 . all This is the first function you will write in ex 0 4 _ utils.py . The other two functions will also be

1. all
This is the first function you will write in ex04_utils.py. The other
two functions will also be defined in this file.
Given a list of ints and an int, all should return a bool indicating
whether or not all the ints in the list are the same as the given int.
Example usage:
>>> from exercises.ex04_utils import all
>>> all([1,2,3],1)
False
>>> all([1,1,1],2)
False
>>> all([1,1,1],1)
True
Continue by defining a skeleton function with the following signature:
Name: all
Arguments: A list of integers and an int.
Returns: A bool, True if all numbers match the indicated number, False
otherwise or if the list is empty. This algorithm should work for a
list of any length. Hint: remember you can return from inside of a
loop to short-circuit its behavior and return immediately.
2. max
Next, you will write a function named max.
The max function is given a list of ints, max should return the
largest in the List.
If the list is empty, max should result in a ValueError. Well show
you how! Examples:
>>> from exercises.ex04_utils import max
>>> max([1,3,2])
3
>>> max([100,99,98])
100
>>> max([])
ValueError: max() arg is an empty List
Define a skeleton function with the following signature:
Name: max
Argument: A list of integers.
Returns: An int, the largest number in the list. If the list is empty,
raises a ValueError.
The body of your skeleton function can begin as such, which
demonstrates how to raise an error:
def max(input: list[int])-> int:
if len(input)==0:
raise ValueError("max() arg is an empty List")
3. is_equal
Given two lists of int values, return True if every element at every
index is equal in both lists.
>>> from exercises.ex04_utils import is_equal
>>> is_equal([1,0,1],[1,0,1])
True
>>> is_equal([1,1,0],[1,0,1])
False
Your implementation should not assume the lengths of each List are equal.
This concept is called deep equality. Two separate list objects on the
heap may be distinct objects, such that if you changed one the other
would remain the same. However, two distinct objects can be deeply
equal to one another if what they are made of is equal to each other
in essence.
Define a function with the following signature:
Name: is_equal
Parameters: Two lists of integers.
Returns: True if lists are equal, False otherwise.
Implement the is_equal function as described above.
4. extend
Given two lists of int values, mutate the first list of int values by
appending the second lists values to the end of it.(Think of this is
something similar to concatentation in strings!)
Note that this function is not returning anything! It is only mutating
one of the inputs.
>>> from exercises.ex04_utils import extend
>>> a: list[int]=[1,3,5]
>>> b: list[int]=[2,4,6]
>>> extend(a, b)
>>> a
[1,3,5,2,4,6]
>>> c: list[int]=[7,8]
>>> extend(c, b)
>>> c
[7,8,2,4,6]
Define a function with the following signature:
Name: extend
Parameters: Two lists of integers.
Returns: Nothing.
Implement the extend function as described above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!