How can I write code to change the index variable to skip over already tested values?

Viewed 18

I'm trying to write a code to, when given a list of integers, return the largest integer. How can I wrote code so, for example, if value a is greater than b, but c is greater than b, then we can infer c is greater than b? I want to do this in python.

def max(int_list: list[int]) -> int:
"""When list is empty, result in ValueError."""
if len(int_list) == 0:
    raise ValueError("max() arg is an empty List")
#if there are no values in list, return ValueError

i: int_list = 0
num_at_index: int_list[i]
num_at_alt_index = int_list[i + 1]
max_value: int = 0

while len(int_list) > 0 and i < len(int_list):
    if num_at_index > num_at_alt_index:
        num_at_index = max_value
        i += 1

    else: 
        max_value = num_at_alt_index
        i += 1

Here is my code so far, I'm having a hard time figuring out where I can implement this (also, if anyone sees anything off about my code so far, please let me know).

0 Answers
Related