#554 · Loops · Beginner · 30 XP · about 5 min
Write largest_digit(n) that returns the largest digit in the whole number n. A negative number has the same digits as its positive version, because the minus sign is not a digit. For 0 the answer is 0.
Try it with arithmetic: n % 10 is the last digit of n, and n // 10 is n with that digit removed.
largest_digit(3852) # returns 8 largest_digit(-47) # returns 7 largest_digit(1000) # returns 1 largest_digit(7) # returns 7
First solves only, ranked by stars and then time.