2021-10-07 15:20:32 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
def find_min(nums: list[int | float]) -> int | float:
|
2019-10-28 12:50:36 +00:00
|
|
|
"""
|
|
|
|
Find Minimum Number in a List
|
|
|
|
:param nums: contains elements
|
2019-12-11 06:57:08 +00:00
|
|
|
:return: min number in list
|
2019-07-10 20:09:24 +00:00
|
|
|
|
2019-10-28 12:50:36 +00:00
|
|
|
>>> for nums in ([3, 2, 1], [-3, -2, -1], [3, -3, 0], [3.0, 3.1, 2.9]):
|
|
|
|
... find_min(nums) == min(nums)
|
|
|
|
True
|
|
|
|
True
|
|
|
|
True
|
|
|
|
True
|
2021-10-07 15:20:32 +00:00
|
|
|
>>> find_min([0, 1, 2, 3, 4, 5, -3, 24, -56])
|
|
|
|
-56
|
|
|
|
>>> find_min([])
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
ValueError: find_min() arg is an empty sequence
|
2019-10-28 12:50:36 +00:00
|
|
|
"""
|
2021-10-07 15:20:32 +00:00
|
|
|
if len(nums) == 0:
|
|
|
|
raise ValueError("find_min() arg is an empty sequence")
|
2019-10-28 12:50:36 +00:00
|
|
|
min_num = nums[0]
|
|
|
|
for num in nums:
|
|
|
|
if min_num > num:
|
|
|
|
min_num = num
|
|
|
|
return min_num
|
2019-07-10 20:09:24 +00:00
|
|
|
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
if __name__ == "__main__":
|
2021-10-07 15:20:32 +00:00
|
|
|
import doctest
|
|
|
|
|
|
|
|
doctest.testmod(verbose=True)
|