Dremendo Tag Line

Sum of first and last digit in Python

input() - Question 5

In this question, we will see how to input a two digit number in Python programming using the input() function and find the sum of its first and last digit. To know more about input() function click on the input() function lesson.

Q5) Write a program in Python to input a two digit number and find the sum of its first and last digit.

Program

print('Enter a two digit number')
n=int(input())
fd=n//10
ld=n%10
sum=fd+ld
print('First digit={}'.format(fd))
print('Last digit={}'.format(ld))
print('Sum of first and last digit={}'.format(sum))

Output

Enter a two digit number
56
First digit=5
Last digit=6
Sum of first and last digit=11
video-poster