第17677题 程序题
完善Python判断正整数是否为素数的自定义函数程序代码

素数是只能被1和本身整除的正整数,编写自定义函数,实现判断正整数是否为素数。完善程序代码。

"""
判断正整数n是否为素数,若是返回True;否则返回False
函数名  def prime(n)
参数    n:表示正整数
返回值 :n是素数,返回True;否则返回False
"""
def prime(n):
    if n < 2:
        return False
    else:
        for i in range(  ①  ,n):
            if   ②   :
                return False
    return   ③  
n = 7
if   ④  :
    print("{}是素数".format(n))
else:
    print("{}不是素数".format(n))
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
编辑模式
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析