Python Program to find the sum of first and last digit of a number
In this program, You will learn how to find the sum of first and last digit of a number in Python.
1234 => 1 + 4 = 5
Example: How to find the sum of first and last digit of a number in Python.
n = int(input("Enter a number:"))
rev = 0
fd = 0
s = 0
ld = n % 10
while n > 0:
r = n % 10
rev = rev * 10 + r
n = int(n / 10)
fd = rev % 10
s = fd + ld
print("Sum of first and last digits:", s)
Output:
Enter a number:3456
Sum of first and last digits: 9