Sum Fist Last Digits Program in Python


If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.

This program is a simple program that takes a four-digit number as input from the user and calculates the sum of the first and last digits of that number. The program uses the modulus operator and the integer division operator to extract the first and last digits of the input number. The extracted digits are then added together to give the sum of the first and last digits. The final result is printed on the screen with the statement "Sum of First and Last digits =" followed by the calculated sum.


Source Code

n=int(input("Enter the four Digits Number :"))
sum=0
a=n//1000
sum=sum+a
a=n%10
sum=sum+a
print("Sum of First and Last digits =",sum)

Output

Enter the four Digits Number :2315
Sum of First and Last digits = 7


Example Programs