Python program to print Last Digit in a Number

n = int(input("Enter any number : "))
# convert number into string
number = str(n)
# convert first and last characters into integer digits
first = int(number[0])
last = int(number[-1])
sum = first + last
print(f"sum of {first} and {last} is : ",sum)

OUTPUT:

Enter any number : 562
sum of 5 and 2 is : 7
Enter any number : 73218
sum of 7 and 8 is : 15

Leave a Comment