Because you output the result returned by the max
function. And if the function explicitly returns nothing, then None
is implicitly assigned to its return value. Depending on what you need, the code can be rewritten in two versions.
First option:
def max(x, y): if len(x) > len(y): print('Меньше второе') else: print('Меньше первое') x = str(input('Введите первое слово: ')) y = str(input('Введите второе слово: ')) max(x, y)
The second option:
def max(x, y): if len(x) > len(y): return 'Меньше второе' else: return'Меньше первое' x = str(input('Введите первое слово: ')) y = str(input('Введите второе слово: ')) print(max(x, y))
By the way, your max
function can be written shorter:
def max(x, y): return 'Меньше второе' if len(x) > len(y) else 'Меньше первое'