Python bootcamp · Lab 34

Min and max

easyLists8 minLesson: Lists

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

The first line is n. The second line has n integers. Print the smallest, then the largest, separated by a space.

Input. Line 1: n. Line 2: n integers.

Output. Two integers: min then max.

Constraints

  • 1 ≤ n ≤ 1000

Examples

Example 1
Input
5
3 1 8 2 4
Output
1 8
Example 2 — A single value is both min and max.
Input
1
42
Output
42 42
Hint
  1. min(nums) and max(nums) are built in.
  2. print(min(nums), max(nums)).
Show correct code

Peek only after you have tried. You can still Check your own version.

n = int(input())
nums = list(map(int, input().split()))
print(min(nums), max(nums))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.