[英]Testing the remainder from a modulo operation using conditionals
接受一个数字,并指出除以3时的余数是0、1还是2。
我的代码:
number = int(input("Please enter the number"))
print(number % 3)
如何测试模的结果以确定数字是否可被3整除?
使用if
来测试%
操作的余数:
number = int(input("Please enter the number"))
if number % 3: # is true if the remainder is 1 or 2
print('Not divisible')
else:
print('Divisible')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.