Computer Science, asked by sahilcool1406, 2 days ago

Write a program to print ""HELLO"" if the last digit of user given number is divisible by 3 else ""BYE""? In python

Answers

Answered by Anonymous
25

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!

Attachments:
Answered by Anonymous
15

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 \tt{print()} statement.

We would first ask the user to input a number and we'll store it on \tt{int()} 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.

\rule{300}{2}

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")

Similar questions