I
I
Ilya Melnikov2018-10-28 20:46:56
Python
Ilya Melnikov, 2018-10-28 20:46:56

Why doesn't it work correctly?

a = int(input())
n = a % 10
a2 = a // 10
while(a2 != 0):
    z = a2 % 10
    if(n > z):
        ld = n
    else:
        ld = z
    a2 = a2 // 10
    print(ld)

You need to find the largest digit of the number. Could you tell me what is wrong here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Fedoryan, 2018-10-29
@ilko134

ldIt is desirable to declare a variable before the loop. Wrong indentation
. Too many unnecessary variables. The algorithm itself is correct, but I would rewrite it like this:print

input_value = int(input())
max_number = 0
while (input_value > 0):
    current_number = input_value % 10
    if (max_number < current_number):
        max_number = current_number
    input_value //= 10
print(max_number)

L
lega, 2018-10-28
@lega

>>> max(list('1736'))
'7'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question