fb pixel

Number digits

Given a number n = 13453687, for instance, it’s possible to extract the last digit by taking the remainder when dividing by 10. We can extract the digit before the last one by dividing the number by 10 and then take the remainder after division by 10. The digit before that can be extracted by dividing the number by 100 and then taking the remainder after division by 10, and so on.
n = 13453687
print(n % 10)          # 7
print(n // 10 % 10)    # 8
print(n // 100 % 10)   # 6
print(n // 1000 % 10)  # 3
# ...

Challenge

Given a 4-digit number, print the central two digits.
Input
Output
1234
23
1298
29
 
To check your solution you need to sign in
Sign in to continue