Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python checking whether two numbers are mutually factors

Python checking whether two numbers are mutually factors

Document Object Reference Manual Python3 Examples

In mathematics, if two numbers are mutually factors, it means they can divide each other, i.e., one number divides the other with no remainder. We can write a simple Python program to check whether two numbers are mutually factors.

Example

def

are_mutual_factors

(

a

,

b

)

:

   

if

a % b

==

0

and

b % a

==

0

:

       

return

True

   

else

:

       

return

False

Testing

num1

=

12

num2

=

6

result

=

are_mutual_factors

(

num1

,

num2

)

print

(

f

"{num1} and {num2} are mutually factors: {result}"

)

Code analysis:

Output result:

12 和 6 是否互为因数: True

Document Object Reference Manual Python3 Examples