Challenge: Highest Even Number
This challenge has no exercises, and no pyBox. Just you, VS Code and everything you have learned so far.
The goal is simple to describe but requires you to think logically and connect multiple concepts together. This is what real programming looks like.
The Challenge
Create a file named highest_even.py in your part53 folder.
Write a function that takes a list of numbers as an argument. The list will contain both even and odd numbers. Your function must return and print only the largest even number from that list.
Test your function with the following list:
[1, 7, 11, 2, 8, 10]
The correct answer is 10.
Rules
- You must use a function with at least one parameter.
- Your function must return the result, not just print it.
- You may only use concepts covered in this course so far.
- Do not use Google or AI. The point of this exercise is to think through the problem yourself using what you already know. Searching for the answer will rob you of the most valuable part of this challenge which is the process of figuring it out.
Hints
If you are stuck, think about the following questions before reaching for Google:
- How do you check if a number is even? You have used this operator before in a previous lesson.
- How do you collect items from a list that meet a condition? You have done this with loops and conditionals.
- Once you have a list of even numbers, how do you find the largest one? There is a built in function for this.
Work through each question one step at a time. Each one is a concept you already know. The challenge is connecting them together.
Don't Forget to commit and Push!