Python bootcamp · Lab 17

Maximum in a list

mediumLists12 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 count. The second line has n integers separated by spaces. Print the maximum.

The map(int, ...) pattern converts a whole line of text into numbers in one shot.

Input. Line 1: n. Line 2: n integers separated by spaces.

Output. One integer: the maximum.

Constraints

  • 1 ≤ n ≤ 1000

Examples

Example 1
Input
5
3 1 8 2 4
Output
8
Example 2 — A single value is its own maximum.
Input
1
42
Output
42
Hint
  1. nums = list(map(int, input().split())) reads and converts every value.
  2. print(max(nums)) finishes the job.
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(max(nums))
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.