Write a program to test whether a given number is divisible by another given number and display accordingly
Pls answer if you know it's urgent
Answers
Answered by
3
We will store two different values in two different variables and will check if the remainder when first number is divided by second is 0. A number is said to be divisor of another number if it completely divides the number without leaving any remainder.
a = int(input("Enter 1st no. : "))
b = int(input("Enter 2nd no. : "))
if a%b ==0:
print(f"Yes, {a} is divisible by {b}")
else:
print(f"No, {a} is not divisible by {b}")
>>> Enter 1st no. : 4
>>> Enter 2nd no. : 2
>>> Yes, 4 is divisible by 2
_____
>>> Enter 1st no. : 7
>>> Enter 2nd no. : 4
>>> No, 7 is not divisible by 4
- In the first and second line of the program, we are taking integral input from the user using input() function and storing them in two different variables a and b respectively.
- In the rest program, we are using if else statement and displaying the message accordingly if b when divides by a leaves remainder 0 or not.
- % is called modulo operator in python checks if the remainder is 0 or not.
Similar questions
CBSE BOARD XII,
9 days ago
English,
19 days ago
Computer Science,
19 days ago
Math,
9 months ago
Math,
9 months ago