如何修复Python中的while语法错误?

时间:2018-09-23 23:07:27

标签: python

我在第二个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)")

1 个答案:

答案 0 :(得分:1)

以下两行中缺少右括号)。正确的代码行是

num = (int(input("Enter an integer")))

此外,正如下面的提到,您的外部括号是多余的。您可以简单地使用

num = int(input("Enter an integer"))