mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
8a5b1abd0a
* Update find_max.py * Update find_max.py * Format with psf/black and add doctests
26 lines
397 B
Python
26 lines
397 B
Python
# NguyenU
|
|
|
|
|
|
def find_max(nums):
|
|
"""
|
|
>>> for nums in ([3, 2, 1], [-3, -2, -1], [3, -3, 0], [3.0, 3.1, 2.9]):
|
|
... find_max(nums) == max(nums)
|
|
True
|
|
True
|
|
True
|
|
True
|
|
"""
|
|
max = nums[0]
|
|
for x in nums:
|
|
if x > max:
|
|
max = x
|
|
return max
|
|
|
|
|
|
def main():
|
|
print(find_max([2, 4, 9, 7, 19, 94, 5])) # 94
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|