Python Practice › Loop Programs › Program 21
Sum of the first and last digits
Write a Python program to find the sum of the first and last digits of a number.
Input
74351
Output
7 + 1 = 8
Approach
- Find both digits as in the previous program and add them.
Solution
n = 74351last = n % 10first = nwhile first >= 10: first //= 10print(first, "+", last, "=", first + last)Output
7 + 1 = 8
Learn the concept
New to this topic? Read the lesson, then come back.