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)