Advertisement
Konark

Untitled

Mar 4th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. numbers = '8 3 -5 42 -1 0 0 -9 4 7 4 -4'
  2.  
  3. def high_and_low(numbers):
  4. min_num = None
  5. max_num = None
  6. numbers_list = [int(num) for num in numbers.split(" ")]
  7.  
  8. for num in numbers_list:
  9. if not min_num and not max_num:
  10. min_num = num
  11. max_num = num
  12.  
  13. if min_num > num:
  14. min_num = num
  15.  
  16. if max_num < num:
  17. max_num = num
  18.  
  19. numbers = " ".join((str(num) for num in [max_num, min_num]))
  20.  
  21. return numbers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement