Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Conditional Statements

Find if a number is divisible by both 3 and 5 - Python Program

Example 1 :

num = int(input("Enter number: ")) if num % 3 == 0 and num % 5 == 0: print("Divisible by both 3 and 5") else: print("Not divisible by both")

Output

 
OUTPUT  :
Enter number: 15
Divisible by both 3 and 5

Example 2 :

# Prompt the user to enter a number number = int(input("Enter an integer: ")) # Check for divisibility by both 3 and 5 if number % 3 == 0 and number % 5 == 0: print(f"The number {number} is divisible by both 3 and 5.") # Check for divisibility by 3 only elif number % 3 == 0: print(f"The number {number} is divisible by 3 but not by 5.") # Check for divisibility by 5 only elif number % 5 == 0: print(f"The number {number} is divisible by 5 but not by 3.") # If not divisible by either else: print(f"The number {number} is neither divisible by 3 nor by 5.")

Output

 
OUTPUT 1 :
Enter an integer: 5
The number 5 is divisible by 5 but not by 3.

OUTPUT 2 :
Enter an integer: 15
The number 15 is divisible by both 3 and 5.

OUTPUT 3 :
Enter an integer: 26
The number 26 is neither divisible by 3 nor by 5.