8.3.5: Max In List
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.

Respuesta :

Answer:

here!!

Explanation:

# Write code here...

def max_int_in_list(my_list):

   highest = my_list[4]

   

   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

fichoh

A version of the required program written in python 3 is given below.

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

def max_int_in_list(my_list):

#iniate the function named max_int_in_list which takes in a list argument

maximum = my_list[0]

#set the first value in the list as maximum

for num in my_list:

#iterate through every value in the list

if num > maximum:

#Check if any of the iterated values in the list is greater than the set maximum value

maximum = num

#if so set the Number as the new maximum value

return maximum

#return the maximum value

print(max_int_in_list(my_list))

A SCREENSHOT of the program output is attached.

Learn more on python programs :https://brainly.com/question/24782250

Ver imagen fichoh
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE