我在第二个while循环中遇到语法错误。不知道为什么,任何帮助表示赞赏:)
#intro
print("Welcome to my prime number detector.")
print("Provide an integer and I will determine if it is prime.")
#again loop
again = "Y"
while again == "Y":
num = (int(input("Enter an integer"))
#check for valid input
while num < 1:
num = (int(input("Enter an integer"))
#test for prime
for d in range(2,num):
if (num % d) == 0:
print(num,"is not prime.")
else:
print(num,"is prime.")
#ask again
again = intput("Do you want to play again? (Y/N)")
答案 0 :(得分:1)
以下两行中缺少右括号)
。正确的代码行是
num = (int(input("Enter an integer")))
此外,正如下面的提到,您的外部括号是多余的。您可以简单地使用
num = int(input("Enter an integer"))