Start free

Beginner · Lists · 101 of 264

Smallest and largest

Read numbers from one line and print the smallest and the largest.

Input: whole numbers on one line, separated by spaces. Output: the smallest and the largest, separated by a space.

Examples

Input
3 9 1 7
Output
1 9
Input
5
Output
5 5
Input
-2 -8 -1
Output
-8 -1

One more test checks other inputs when you press Check.

Stuck? The idea behind lists

A list keeps several values in order: [3, 9, 1]. Its items are numbered from 0, like a string's characters.

append() adds to the end; sum(), min(), max(), len() and sorted() work on a whole list. Read numbers from one line with input().split() and int().

numbers = [int(x) for x in input().split()]
print(sum(numbers), max(numbers))
numbers.append(0)
print(numbers)

Watch for: split() gives text: "10" sorts before "9". Turn each item into a number before comparing or adding.

All the lists exercises
Your code
Opening the code editor…
Python 3.14 in your browser
Output
Run shows what your program prints. Check tests it on every example and the hidden tests.

More lists exercises