+ 1

How do I find the largest number in a list without using max()?

Imagine you have a list like this: nums = [4, 9, 2, 11, 7] If I don’t want to use the built-in max() function, how can I figure out the biggest number in that list just using a loop?

29th Jul 2025, 10:47 PM
SAIFULLAHI KHAMISU
SAIFULLAHI KHAMISU - avatar
3 ответов
+ 2
Your attempt!?? p.s. iterate through loop, and compare the number to a previously found maximum number.
29th Jul 2025, 11:13 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
A short pythonic way might be to use sorted then grab the last number. print(sorted(nums)[-1])
30th Jul 2025, 12:07 AM
BroFar
BroFar - avatar
+ 1
* Initialize a variable, let's call it largest, with the first number in the list. * Loop through the rest of the numbers in the list one by one. * Inside the loop, compare the current number with the largest variable. * If the current number is bigger, update largest to be that number. * After the loop finishes, the largest variable will hold the biggest number in the entire https://sololearn.com/compiler-playground/c0gDYWUI0qT0/?ref=app This will help you
31st Jul 2025, 5:27 PM
Omi Patil
Omi Patil - avatar