num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if num2 == 0:
print("Division by zero is not allowed.")
elif num1 % num2 == 0:
print(f"{num1} is completely divisible by {num2}.")
else:
print(f"{num1} is NOT completely divisible by {num2}.")
#source code --> clcoding.com
Code Explanation:
Taking Input from the User
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
The program asks the user to enter two numbers.
int(input()) is used to convert the input into an integer.
The values are stored in num1 and num2.
Checking for Division by Zero
if num2 == 0:
print("Division by zero is not allowed.")
Since dividing by zero is mathematically undefined, we first check if num2 is zero.
If num2 == 0, the program prints an error message and does not proceed further.
Checking for Complete Divisibility
elif num1 % num2 == 0:
print(f"{num1} is completely divisible by {num2}.")
The modulus operator (%) is used to check divisibility.
If num1 % num2 == 0, it means num1 is completely divisible by num2, so the program prints a confirmation message.
Handling Cases Where num1 is Not Divisible by num2
else:
print(f"{num1} is NOT completely divisible by {num2}.")
If the remainder is not zero, it means num1 is not completely divisible by num2, so the program prints a negative response.
0 Comments:
Post a Comment