mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
finding max (#1488)
* Update find_max.py * Update find_max.py * Format with psf/black and add doctests
This commit is contained in:
parent
39c40e7e40
commit
8a5b1abd0a
@ -2,15 +2,23 @@
|
|||||||
|
|
||||||
|
|
||||||
def find_max(nums):
|
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]
|
max = nums[0]
|
||||||
for x in nums:
|
for x in nums:
|
||||||
if x > max:
|
if x > max:
|
||||||
max = x
|
max = x
|
||||||
print(max)
|
return max
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
find_max([2, 4, 9, 7, 19, 94, 5])
|
print(find_max([2, 4, 9, 7, 19, 94, 5])) # 94
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user