k=input().split()
print(max(k))
input:
3 10
output:
3
k=input().split()
print(max(k))
input:
3 10
output:
3
Because string "3" is greater than string "10", for the same reason that string "z" is greater than "a"; alphabetic rather than numeric sorting. The first 20 numbers, as strings, sort like:
1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9
This is because strings are sorted from the leftmost character to the rightmost, so for example 2 and 20 are tied on the first character and the next one sorts it out, whereas the 3 in 3 is greater than the 2 in 20
# this will do string comparison
k=input().split()
print(max(k))
# to make integers
# go element by element
k = [int(i) for i in input().split()]
print(max(k))
# using map
k = map(int, input().split())
print(max(k))
You need to specify that the input is an integer using the int()
function, otherwise python will automatically view it as a string
.
Strings have their own way of sorting numbers which is completely different from integers.