Classic algorithms · 8 / 22 Exercise Easy

Minimum and maximum by hand

Objective

Create a Python program that finds the smallest and the largest value of a list by going through it only once.

Instructions

  • Read a line with integers separated by spaces (at least one).
  • Without using min() or max(): start from the first number being both the minimum and the maximum and update both while going through the rest.
  • Show Minimum: X on the first line and Maximum: Y on the second.
Input
5 3 9 1 7
Output
Minimum: 1
Maximum: 9

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise