Write a program to print ""HELLO"" if the last digit of user given number is divisible by 3 else ""BYE""? In python
Answers
Keep in mind, that n%10 will always return the last digit of any given number.
The program and its output has been attached above. Kindly check it!
Python Program
This python program allows the user to enter any number. Next, Python is going to check if the last digit of a given number is divisible by 3. If the last digit is divisible by 3, it'll print "Hello" or else "Bye" on the screen using statement.
We would first ask the user to input a number and we'll store it on function.
Then, we'll find the last digit of a number. To find the last digit of a number, we'll use the modulo operator %. When modulo is divided by 10 it gives its last digit.
Lastly, we'll check if the last digit is divisible by 3 and print "Hello" and "Bye" accordingly.
Program
# Ask the user to input a number
num = int(input("Enter a number: "))
# Find the last digit of the number
last_digit = num % 10
# Check if the last digit is divisible by 3
if last_digit % 3 == 0:
# Print "Hello" if it is divisible
print("Hello")
else:
# Print "Bye" if it is not divisible
print("Bye")