Find highest and lowest number from the string of numbers

后端 未结 5 858
慢半拍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条回答
  •  有刺的猬
    2021-01-21 10:41

    You can split your string by ' ' and pass it as Array

    def high_and_low(numbers):
        # split string by space character
        numbers = numbers.split(" ")
        # convert string array to int, also making list from them
        numbers = list(map(int, numbers))
        return max(numbers), min(numbers)
    
    print(high_and_low("1 2 10 4 5"))
    

提交回复
热议问题