Python:简单的可分性测试

时间:2014-11-24 20:41:34

标签: python

我正在尝试编写一个简单的代码,提示用户输入两个数字以确定它们是否可以被整除:

print 'Enter the following'
num1 = input("Integer:")
num2 = input("Integer:")
evaluation = ((num1 / num 2) / 2)
print num1, "/2", num2, "/2" = ",evaluation

我是Python的新手,正在寻求有关如何调整此代码的建议。任何帮助将不胜感激。感谢您的时间!

1 个答案:

答案 0 :(得分:1)

您需要modulo operator

print "Enter the following"
num1 = input("Integer:")
num2 = input("Integer:")
evaluation = num1 % num2
if evaluation == 0:
    print num1, "/", num2, " evenly divides"
else:
   print num1, "/", num2, " does not evenly divide"