+ 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?
3 Respuestas
+ 2
Your attempt!??
p.s. iterate through loop, and compare the number to a previously found maximum number.
+ 1
A short pythonic way might be to use sorted then grab the last number.
print(sorted(nums)[-1])
+ 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