216k views
2 votes
Write the function max_int_in_list that takes a list of ints and returns the biggest int in the list. You can assume that the list has at least one int in it. A call to this function would look like:

my_list = [5, 2, -5, 10, 23, -21]
biggest_int = max_int_in_list(my_list)
# biggest_int is now 23
Do not use the built-in function max in your program!

Hint: The highest number in the list might be negative! Make sure your function correctly handles that case.

User AHM
by
3.9k points

1 Answer

11 votes

# your function should return the maximum value in `my_list`

def max_int_in_list(my_list):

highest = my_list[0]

for num in my_list:

if num > highest:

highest = num

return highest

my_list = [5, 2, -5, 10, 23, -21]

biggest_int = max_int_in_list(my_list)

print (biggest_int)

Step-by-step explanation:

User Mister Jojo
by
4.1k points