Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**PYTHON** - Cannot use other built-in functions besides len - specifically not max, min, slice - Cannot use slice notation in conjunction with the subscription

**PYTHON**

- Cannot use other built-in functions besides len

- specifically not max, min, slice

- Cannot use slice notation in conjunction with the subscription operator

- Cannot use the in the operator of Python

- Cannot use the list classs + or == operators nor built-in methods beyond append and pop

** Note: You can use + and == for individual elements, just not entire lists.

Part - ALL

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:

>>> 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:

a. Name: all

b. Arguments: A list of integers and an int.

c. 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.

Part - 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.

Examples:

>>> 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:

a. Name: max

b. Argument: A list of integers.

c. 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")

PART is_equal

Given two lists of int values, return True if every element at every index is equal in both lists.

>>> 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.

Define a function with the following signature:

a. Name: is_equal

b. Parameters: Two lists of integers.

c. Returns: True if lists are equal, False otherwise. Implement the is_equal function as described above.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions

Question

Desired benefits for the individuals, the team and the organization

Answered: 1 week ago