It is necessary for the code to stop at the first digit of a multi-valued integer number. What should be added?
n = int(input()) while n // 10 != 0: n = n // 10 It is necessary for the code to stop at the first digit of a multi-valued integer number. What should be added?
n = int(input()) while n // 10 != 0: n = n // 10 We translate the module of the number (in case of negative numbers) into the text and take the first character:
n = str(abs(chislo))[0] If the result needs to be used as a number, then we convert the string again to a number:
n = int(str(abs(chislo))[0]) n = -50178 sign = False if n < 0: n *= -1 sign = True while n > 10: n //= 10 if sign: n *= -1 print(n) # -5 sign = abs(n) == n replaces four lines with one. - EnikeyschikSource: https://ru.stackoverflow.com/questions/813482/
All Articles
на первой цифре многозначного целочисленного числаis 10, for example? Or any number that has more than one digit? - Alex Powhile n >= 10:(assert n >= 0) - jfs