In this article, we will show you, How to write a Python Program to find Last Digit in a Number with practical example.
Python Program to find Last Digit in a Number
This python program will allow a user to enter any integer value. Next, it is going to find the Last Digit of the user entered value.
# Python Program to find Last Digit in a Number number = int(input("Please Enter any Number: ")) last_digit = number % 10 print("The Last Digit in a Given Number %d = %d" %(number, last_digit))
OUTPUT
Python Program to find Last Digit in a Number using Function
This program is same as above but this time we separated the logic and placed it in the separate function.
# Python Program to find Last Digit in a Number def lastDigit(num): return num % 10 number = int(input("Please Enter any Number: ")) last_digit = lastDigit(number) print("The Last Digit in a Given Number %d = %d" %(number, last_digit))
OUTPUT