我写python代码来检查是否有素数,但是此代码显示在非素数的示例上,我想显示所有示例但不起作用 不间断显示,但最后一行显示全部为素。
x=int(input('Enter your number to check: '))
if x>1:
for prime in range(2,x):
if x % prime == 0:
print(x,"isn't prime :",prime,'*',x // prime)
else:
print(x,'is prime')
else:
print(x,"isn't prime")
例如在终端输入x 18 show:
答案 0 :(得分:0)
x = int(input('Enter your number to check: '))
is_prime = True
for prime in range(2, x):
if x % prime == 0:
is_prime = False
print(x, "isn't prime :", prime, '*', x // prime)
if is_prime:
print(x, "is prime")