Question: 1 . all This is the first function you will write in ex 0 4 _ utils.py . The other two functions will also be
all
This is the first function you will write in exutils.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.exutils import all
all
False
all
False
all
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 shortcircuit its behavior and return immediately.
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.exutils import max
max
max
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 maxinput: listint int:
if leninput:
raise ValueErrormax arg is an empty List"
isequal
Given two lists of int values, return True if every element at every
index is equal in both lists.
from exercises.exutils import isequal
isequal
True
isequal
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: isequal
Parameters: Two lists of integers.
Returns: True if lists are equal, False otherwise.
Implement the isequal function as described above.
extend
Given two lists of int values, mutate the first list of int values by
appending the second lists values to the end of itThink 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.exutils import extend
a: listint
b: listint
extenda b
a
c: listint
extendc b
c
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
