Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用条件测试模运算的余数_Python_If Statement_Conditional - Fatal编程技术网

Python 使用条件测试模运算的余数

Python 使用条件测试模运算的余数,python,if-statement,conditional,Python,If Statement,Conditional,接受一个数字,并指示其被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 d

接受一个数字,并指示其被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')

很不错的。那么,你的问题是什么?我如何使用“if”语句来解决这个问题?我觉得他们好像想要一个“yes”/“no”输出。如果余数为0、1或2,则输出“是”,否则输出“否”understand@rickdenhaan这将为每个可能的输入输出“是”。。。