DEV Community

Cover image for Python 🐍 challenge_23βš”οΈ
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on • Updated on

Python 🐍 challenge_23βš”οΈ

Highest and Lowest

  • In this little assignment you are given a string of space separated numbers.
  • And have to return the highest and lowest number.

Examples:

high_and_low("1 2 3 4 5")  # return "5 1"
high_and_low("1 2 -3 4 5") # return "5 -3"
high_and_low("1 9 3 4 -5") # return "9 -5"

Enter fullscreen mode Exit fullscreen mode

Notes:

  • All numbers are valid Int32, no need to validate them.
  • There will always be at least one number in the input string.
  • Output string must be two numbers separated by a single space, And highest number is first.
Task URL: Link

My Solution:

def high_and_low(numbers: str) -> str:

    high: str = str(max([int(number) for number in numbers.split()]))
    low: str = str(min([int(number) for number in numbers.split()]))
    return f"The highest number in the lest: {high} The lowest number in the lest: {low}"

Enter fullscreen mode Exit fullscreen mode

Learn Python

Python top free courses from CourseraπŸπŸ’―πŸš€

πŸŽ₯

Connect with Me 😊

πŸ”— Links

linkedin

twitter

Top comments (0)