[PYTHON] Find the maximum value, minimum value, and number of elements when the integer N is on the first line of the standard input and N integers follow.

In the standard input, the integer N is given on the first line, followed by N integers, and (N + 1) integers are given in the following form.

** Find the maximum value of the integer excluding N on the first line **

N
a_1
...
a_N

** Find the maximum value of (a_1 ... a_n) from the above. ** **

↓ Example of input value

3(N)
7(a_1)
9(a_2)
4(a_N)

↓ Example of output value you want to obtain

9(a_2 =Maximum value)

There are the following two patterns.

** (1) Create a list with N elements 0 **

N = int(input())

#Create a list with N elements 0
A = [0] * N

#Replace the elements entered in the list with 0
for i in range(N):
    a = int(input())
    A[i] = a

print(max(A))

** (2) Create an empty list **

N = int(input())

#Create an empty list
A = []

#Add a new element to be entered in the list
for i in range (N):
    A.append(int(input()))

print(max(A))

Recommended Posts

Find the maximum value, minimum value, and number of elements when the integer N is on the first line of the standard input and N integers follow.
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
Find the index of the maximum value (minimum value) of a multidimensional array
[Python] How to use list 2 Reference of list value, number of elements, maximum value, minimum value
A comment I saw on Google+ was, "Is there an easy way to find out what number element of a list is maximum / minimum in Python?" The first line I came up with was the code on the first line, but is the second line better?
[Python] Number of integer sequences of length n for which the sum is m
The timing when the value of the default argument is evaluated is different between Ruby and Python.