DEV Community

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

Posted on β€’ Edited on

1

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay