Find highest and lowest number from the string of numbers

后端 未结 5 897
慢半拍i
慢半拍i 2021-01-21 09:44

I\'m trying to write a function that returns the highest and lowest number in a list.

def high_and_low(numbers):

    return max(numbers), min(numbers)

print(hi         


        
5条回答
  •  Happy的楠姐
    2021-01-21 10:23

    use numbers_list=[int(x) for x in numbers.split()] and use numbers_list in min() and max(). split() turns '1 23 4 5' into ['1','23','4','5']; and by using a list comprehension all the strings get converted to integers.

提交回复
热议问题