33.0k views
1 vote
Write a program to see if the numbers are divisble by three python

User Madcyree
by
8.1k points

1 Answer

1 vote

Final answer:

To check if a number is divisible by three in Python, you can use the modulo operator (%) to calculate the remainder when the number is divided by three. If the remainder is zero, then the number is divisible by three.

Step-by-step explanation:

To check if a number is divisible by three in Python, you can use the modulo operator (%) to calculate the remainder when the number is divided by three. If the remainder is zero, then the number is divisible by three. Here's an example program:



def divisible_by_three(number):
if number % 3 == 0:
return True
else:
return False

# Test the function
number = int(input('Enter a number: '))
if divisible_by_three(number):
print(number, 'is divisible by three.')
else:
print(number, 'is not divisible by three.')



In this program, the divisible_by_three function takes a number as input and returns True if the number is divisible by three, and False otherwise. The program then prompts the user to enter a number and checks if it is divisible by three using the divisible_by_three function.

User Negash
by
8.3k points