-2
k=input().split()    
print(max(k))

input:

3 10

output:

3
khelwood
  • 52,115
  • 13
  • 74
  • 94
VATSAL JAIN
  • 511
  • 2
  • 12

3 Answers3

1

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

Caius Jard
  • 69,583
  • 5
  • 45
  • 72
1
# 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))
Kuldeep Singh Sidhu
  • 3,531
  • 2
  • 9
  • 20
0

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.

Run_Script
  • 2,332
  • 2
  • 12
  • 26
slvnml
  • 11
  • 3