Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.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_Function_Input - Fatal编程技术网

用Python检查数字是否为素数并显示异常

用Python检查数字是否为素数并显示异常,python,function,input,Python,Function,Input,我有一个python函数,它应该接受integer参数,并根据函数中的逻辑对其进行处理,然后打印出数字是否为素数。 我正在Visual Studio 2019上运行python文件。它会对从用户传递到函数中的参数am引发异常。。以下是迄今为止我从visual studio异常框中得到的+:'int'和'str'不支持的操作数类型 ##Defining python function to check whether a certain number is prime or not def che

我有一个python函数,它应该接受integer参数,并根据函数中的逻辑对其进行处理,然后打印出数字是否为素数。 我正在Visual Studio 2019上运行python文件。它会对从用户传递到函数中的参数am引发异常。。以下是迄今为止我从visual studio异常框中得到的+:'int'和'str'不支持的操作数类型

##Defining python function to check whether a certain number is prime or not
def check_Prime(o):
    isPrime=True
    for i in range(2,o):
        if(o%i==0):
          isPrime=False
    
    if(isPrime):
        print(o+" "+"is prime")
    else:
        print(o+" "+"is not prime")


prime=int(input("Enter the integer you would like to check for prime"))
check_Prime(prime)
使用:

您的错误指向连接
int
str
,但您不能这样做。

使用:


您的错误指向连接
int
str
,这是您无法做到的。

print(f{o}是prime”)
print(f{o}是prime”)
感谢您的帮助,起初我没有理解它,但现在我在条件结构库中计算了它的print语句,起初我并不理解它,但现在我认为它是条件结构中的print语句
print(f'{o} is prime')