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

input:

3 10

output:

3
khelwood
  • 55,782
  • 14
  • 81
  • 108
VATSAL JAIN
  • 561
  • 3
  • 18

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
  • 72,509
  • 5
  • 49
  • 80
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,748
  • 2
  • 12
  • 22
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,487
  • 2
  • 15
  • 30
slvnml
  • 11
  • 3