Python Program to Check Handsome Number

In Mathematics, Handsome numbers are those number in which the sum of all the left side digit is equal to the last digit.

Handsome number examples: 123, 224, 235 etc.

Here 123 is Handsome number because last digit = 3 & remaining left part is 12 and sum of 1+2 is 3 i.e. 123 --> 1+2 = 3 which is last digit.

Similarly, 347 is Handsome because 3+4 = 7 which is last digit.

This Python program checks whether a given number by user is Handsome number or not.

Python Source Code: Handsome Number


# Handsome number

number = int(input('Enter number: '))

last_digit = number % 10

left_part = number // 10

left_part_sum = 0
while left_part:
    left_part_sum += left_part % 10
    left_part = left_part // 10

if left_part_sum == last_digit:
    print('%d is Handsome Number.' %(number))
else:
    print('%d is Not Handsome Number.' %(number))

Handsome Check Output

Run 1:
---------------
Enter number: 369
369 is Handsome Number.


Run 2:
---------------
Enter number: 269
269 is Not Handsome Number.