a=input()
b=input()
if a<b :
print('B is maximum',b)
else:
print('A is maximum',a)
for this program if we give a=10 b=2 it will give B is maximum why ?
a=input()
b=input()
if a<b :
print('B is maximum',b)
else:
print('A is maximum',a)
for this program if we give a=10 b=2 it will give B is maximum why ?
It sounds like you're using Python 3.x. In this version, input()
returns strings, not numbers, so it's doing a lexicographic comparison, not a numeric comparison. If you want to compare integers, you have to convert the input first:
a = int(input())
b = int(input())
To be precise, it is because you are using Python 3.x. In Python 2.x, there were two variants, raw_input() which returns a string and input() which returns an evaluated result. In Python 3.x, raw_input() was renamed to input(), and the original input() function was dropped (though you can easily get the behaviour by wrapping it over an eval function).
Strings are compared lexicographically so '10' < '2' though if they had been numbers the result would had been antagonistic.