Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

write a python program that prompts the user to enter a number and then…

Question

write a python program that prompts the user to enter a number and then checks whether the number is divisible by 2, 3, or both. print out an appropriate message depending on the input. edit format table 12pt paragraph b i u a t²

Explanation:

Step1: Prompt user for input

num = int(input("Please enter a number: "))

Step2: Check divisibility

if num % 2 == 0 and num % 3 == 0:
    print(f"{num} is divisible by both 2 and 3.")
elif num % 2 == 0:
    print(f"{num} is divisible by 2.")
elif num % 3 == 0:
    print(f"{num} is divisible by 3.")
else:
    print(f"{num} is not divisible by 2 or 3.")

Answer:

num = int(input("Please enter a number: "))
if num % 2 == 0 and num % 3 == 0:
    print(f"{num} is divisible by both 2 and 3.")
elif num % 2 == 0:
    print(f"{num} is divisible by 2.")
elif num % 3 == 0:
    print(f"{num} is divisible by 3.")
else:
    print(f"{num} is not divisible by 2 or 3.")