Advertisement
makispaiktis

High and Low

May 1st, 2021 (edited)
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. '''
  2. In this little assignment you are given a string of space separated numbers
  3. and have to return the highest and lowest number.
  4. Example:
  5. high_and_low("1 2 3 4 5")  # return "5 1"
  6. high_and_low("1 2 -3 4 5") # return "5 -3"
  7. high_and_low("1 9 3 4 -5") # return "9 -5"
  8. '''
  9.  
  10. def highLow(numbers):
  11.     NUMS = numbers.split(" ")
  12.     nums = [int(NUMS[i]) for i in range(len(NUMS))]
  13.     nums = sorted(nums)
  14.     return (str(nums[len(nums)-1]) + " " + str(nums[0]))
  15.  
  16.  
  17. # MAIN FUNCTION
  18. print(highLow("1 2 -3 4 -5"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement