我试图做一个挑战程序,可以执行不同的任务有关素数。其中一项任务是说明您输入的数字是否为素数(这是菜单中定义为选项的选项)。不循环的循环位于定义为nomtyre的节中。如果你能看一眼,告诉我你认为它有什么问题,那对我真的很有帮助。你知道吗
import time
def nomtyre():
divider = 2
if divider == number:
print (number," is a prime number.")
divider = 2
time.sleep(3)
choice()
else:
if number % divider == 0:
divider = divider + 1
nomtyre()
else:
print (number," is not a prime number.")
divider = 2
time.sleep(3)
choice()
def nomty():
number = int(input("Please enter your whole number: "))
def choice():
print ("Would you like to:")
print ("a) Type in a number to be decided wheather it is a prime number or not.")
print ("b) Have prime numbers calculated from 2 upwards.")
print ("c) Exit.")
answer = input("So what would you like to do? a/b/c: ")
if answer == "a" or answer =="A":
nomty()
elif answer == "b" or answer == "B":
nomup()
elif answer == "c" or answer == "C":
print ("Thank you for using Prime Number calcultor...")
time.sleep(1.5)
else:
print ("Sorry, that wasn't a choice, please try again")
time.sleep(1.5)
choice()
print ("Welcome to Prime Number Calculator...")
time.sleep(1)
choice()
nomtyre
在该代码中从未被调用。所以里面的任何代码都不会执行。为了得到要执行的函数,必须这样调用它。你知道吗首先,你从不打电话给诺姆蒂尔,这就是为什么它从不跑。另外,nomtyre从不定义除法器或数字(我想您应该将它们作为参数传入)。尝试以下操作:
相关问题 更多 >
编程相关推荐