【发布时间】:2021-05-07 11:26:00
【问题描述】:
下面是我的代码。我试图在代码输入时循环这个,所以如果有人给出了数字以外的任何东西,那么它必须用下面的消息做出响应,然后再次询问数字。但是我被卡住了,它尝试了许多尝试块的变体..但是输出似乎是数字是否有效,然后它给出响应[素数或非素数]以及关于非数字的辅助打印值以及输入是否是非数字的,它会给出一个错误,因为它是非数字......任何帮助或建议请
def prime_checker(number) :
is_prime = True
for i in range(2, number) :
if number % i == 0 :
is_prime = False
if is_prime :
print("It's a prime number")
else :
print("Its not a prime number")
should_continue = True
num = int(input("Check this number: "))
prime_checker(number=num)
while not num == int():
result = input("You have entered a non numeric value, please enter a number to continue else enter 'no' to exit. '.\n")
if result == "no":
should_continue = False
print("Goodbye")
【问题讨论】:
-
这里是响应:检查这个数字:40 它不是一个素数您输入了一个非数字值,请输入一个数字继续否则输入'no'退出。 '。
标签: python for-loop oop while-loop integer