Computer Science, asked by tamojitdbl, 19 days ago

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 Anonymous
3

\textbf{\textsf{\Large\underline{Concept}}}

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.

\textbf{\textsf{\Large{\underline{Program}}}}

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}")

\textbf{\textsf{\Large{\underline{Sample run}}}}

>>> 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

\textbf{\textsf{\Large{\underline{Explanation}}}}

  • 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