K
K
Kir Mozor2021-10-28 08:57:51
Python
Kir Mozor, 2021-10-28 08:57:51

I enter 8 9 10 min() selects 9 max() 10. max - min = -1. How so?

I know it's a stupid question. But why does it work the way it does?
see code

#Входные данные: 8 9 10
s = input()
s = s.split()

max = max(s)
min = min(s)

print(int(max) - int(min))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bbkmzzzz, 2021-10-28
@150_Kirill_150

Because you need to read the documentation for the max function
. If you pass strings to max\min, it will find a string (!) that matches lexigraphically, that is, in alphabetical order.
The string '10' < '9' because 1 comes before 9.
No need to redefine built-in names. Consider them reserved and unavailable for variable naming

max = max(s)
min = min(s)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question