rename and add doctest (#1501)

This commit is contained in:
Du YuanChao 2019-10-28 20:50:36 +08:00 committed by Christian Clauss
parent bf50ea09ae
commit 3fc276ca2c
2 changed files with 23 additions and 15 deletions

View File

@ -10,11 +10,11 @@ def find_max(nums):
True
True
"""
max = nums[0]
max_num = nums[0]
for x in nums:
if x > max:
max = x
return max
if x > max_num:
max_num = x
return max_num
def main():

View File

@ -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():
"""Find Minimum Number in a List."""
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
assert find_min([0, 1, 2, 3, 4, 5, -3, 24, -56]) == -56
if __name__ == "__main__":