[英]Check if number is prime with Python thowing an exception
I have a python function that is supposed to take integer parameter and process it according to the logic in the function and print out whether the number is prime or not. 我在 Visual Studio 2019 上運行我的 python 文件。它在參數上引發異常,我從用戶傳遞到 function .. 這是我從 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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.