Lesson guide
What this Python exercise practices
Find Maximum Value is a beginner practice lesson that focuses on loops, iteration, counters. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Lists or strings
- Basic for loop syntax
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Related public exercises
Summary
Find the largest number in a list of integers. Returns None for an empty list.
Problem statement
Write a function find_max(nums) that takes a list of integers nums and returns the maximum value in the list. If nums is empty, return None. Do not use the built-in max() function; iterate through the list and track the largest value manually.
Task
Practice iterating through a list to identify the maximum value and handle empty inputs.
Examples
Basic example
Input
find_max([3, 1, 4, 2])
Output
4
Explanation
Among the numbers 3, 1, 4, 2 the largest is 4.
Input format
A single list of integers, e.g. [1, 2, 3].
Output format
An integer (the maximum) or None for an empty list.
Constraints
You must not use the built-in max() or sorted(). Aim for O(n) time and O(1) extra space.
Samples
Sample input 0
find_max([-5, -2, -3])
Sample output 0
-2
Explanation 0
The maximum among the negatives is -2.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.