def max(x, y): if len(x)>len(y): print ('Меньше второе') else: print ('Меньше первое') x = str(input('Введите первое слово: ')) y = str(input('Введите второе слово: ')) print(max(x, y)) 

The result is correct, but None added to it additionally. Why?

PS Just started to learn not to scold.

    3 answers 3

    Well, because you do not return anything from the max function, respectively, in the string

     print(max(x, y)) 

    and None occurs.

    PS The name of the max function is VERY BAD because there is already a built-in function in Python with that name.

      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 'Меньше первое' 

        All due to print . He has nothing to return here and None . return fixed the situation.

        • There is nothing to return not print , but max . - user194374
        • one
          The answer is incorrect. - andreymal