【发布时间】:2023-04-08 22:06:01
【问题描述】:
我有一个python函数,它应该采用整数参数并根据函数中的逻辑对其进行处理,并打印出该数字是否为素数。
我在 Visual Studio 2019 上运行我的 python 文件。它在参数上抛出异常,从用户传递到函数中。这是我到目前为止从 Visual Studio 异常框unsupported operand type(s) for +: 'int' and '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)
【问题讨论】:
-
print(f"{o} is prime")