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.

Answers 3

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

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.

answer img

AI generated Answer

def max_int_in_list(my_list): max = my_list[0] for num in my_list: if num > max: max = num return max # Explanation The function max_int_in_list takes a list of ints as a parameter, and returns the biggest int in the list. To find the maximum int, the function begins by setting the max value equal to the first item in the list (my_list[0]). It then loops through each item in the list, checking to see if the current item is greater than the stored max. If it is, max is updated to store the higher value. The loop continues until all items have been visited, at which point the highest value found is returned.
  • Rate an answer:

Do you know an answer? Add it here!

Can't find the answer?

Unable to find an answer to your question?

Don't worry! There are several alternative approaches you can try to resolve your query. Here are some tips to help you find answers in different ways:

  1. Reframe your question: Sometimes, the way you phrase your question can limit your search results. Try rephrasing it using different keywords or providing more context to get better results.
  2. Utilize social media: Post your question on social media platforms, particularly those focused on professional or specialized topics. Twitter, LinkedIn, and Facebook groups can connect you with individuals who may have relevant expertise or experiences to share.
  3. Consult subject matter experts: Reach out to experts in the field related to your question. Many professionals are willing to help and share their knowledge. You can connect with them through email, LinkedIn messages, or by attending relevant conferences or events.
  4. Use our website to find your question through the search box above, or you can sign up to ask your question for our big educational community. Our experts will review your question, and you will get a quick and quality answer.
  5. Collaborate with others: If your question is related to a specific project or problem, consider collaborating with others who might have complementary skills or knowledge. Teamwork can lead to innovative solutions and shared insights.

Remember, the process of finding answers often involves persistence, creativity, and an open mind. By exploring various resources, reaching out to others, and being proactive in your search, you increase your chances of finding the information you need. Happy quest for knowledge!

Login with Google

or

Forgot your password?

I don't have an account, I want to Register

Choose a language and a region
How much to ban the user?
1 hour 1 day 100 years