mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
rename and add doctest (#1501)
This commit is contained in:
parent
bf50ea09ae
commit
3fc276ca2c
|
@ -10,11 +10,11 @@ def find_max(nums):
|
||||||
True
|
True
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
max = nums[0]
|
max_num = nums[0]
|
||||||
for x in nums:
|
for x in nums:
|
||||||
if x > max:
|
if x > max_num:
|
||||||
max = x
|
max_num = x
|
||||||
return max
|
return max_num
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -1,17 +1,25 @@
|
||||||
"""Find Minimum Number in a List."""
|
def find_min(nums):
|
||||||
|
"""
|
||||||
|
Find Minimum Number in a List
|
||||||
|
:param nums: contains elements
|
||||||
|
:return: max number in list
|
||||||
|
|
||||||
|
>>> 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
|
||||||
|
"""
|
||||||
|
min_num = nums[0]
|
||||||
|
for num in nums:
|
||||||
|
if min_num > num:
|
||||||
|
min_num = num
|
||||||
|
return min_num
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Find Minimum Number in a List."""
|
assert find_min([0, 1, 2, 3, 4, 5, -3, 24, -56]) == -56
|
||||||
|
|
||||||
def find_min(x):
|
|
||||||
min_num = x[0]
|
|
||||||
for i in x:
|
|
||||||
if min_num > i:
|
|
||||||
min_num = i
|
|
||||||
return min_num
|
|
||||||
|
|
||||||
print(find_min([0, 1, 2, 3, 4, 5, -3, 24, -56])) # = -56
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user