-3
我的目標是構建一個程序,該數字表示數字是否爲數字。 如果2和sqrt(n)之間沒有數字n(n) 除n,那麼正整數n> 2是素數。素數(Python 3)
這裏是我的代碼:
import math
def main():
print("Prime number or not")
try:
N = -1
while N<2:
print("Error!Enter numbers greater than two")
N = int(input("Enter the right number:"))
values = list(range(2,round(math.sqrt(N))))
for i in values:
if i%N !=0:
continue
x = print("The number is not prime")
elif i%N ==0:
break
x = print("The number is NOT prime")
print(x)
except ValueError:
print("Error!Print correct number")
except NameError:
print("Error!Print the numbers")
main()
不過是顯示了線
elif i%N ==0:
請一個語法錯誤,給我一些建議如何糾正這個錯誤,對一般的代碼。我是學習Python的新手,所以任何幫助和評論家都會很棒! 謝謝。
您的縮進混亂。你能否重新縮進你的代碼,最好有四個空格? – NightShadeQueen
你有嚴重的縮進問題 – CoryKramer
'elif'沒有連接到它上面的'if'塊。你不能在這些塊之間放置其他語句。 – TigerhawkT3