输入合数时素数或合数计算器出错
Prime or composite calculator errors when I enter a composite number
num = int(input("Enter A NUMBER: "))
def primeornot():
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
elif (num % i) != 0:
print("Its prime!")
primeornot()
尝试输入一个合数,比如55,它会打印很多结果。会说不是素数,然后说是素数
如果满足if条件则使用break,如果是素数则block
num = int(input("Enter A NUMBER: "))
def primeornot():
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print("Its prime!")
primeornot()
num = int(input("Enter A NUMBER: "))
def primeornot():
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
elif (num % i) != 0:
print("Its prime!")
primeornot()
尝试输入一个合数,比如55,它会打印很多结果。会说不是素数,然后说是素数
如果满足if条件则使用break,如果是素数则block
num = int(input("Enter A NUMBER: "))
def primeornot():
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print("Its prime!")
primeornot()