我寫了一個簡單的python
功能爲我的朋友告訴爲什麼現在一些是素:如何迭代Clojure中的一系列數字?
def why_not_prime(n):
if n==2:
print(n, "is a prime.")
for i in range(2,n):
if n%i == 0:
print(n, "is not a prime because it could be divided by", i,".")
break
else:
print(n, "is a prime.")
break
我嘗試將其轉換爲Clojure
,但我無法找到路。我不知道如何處理for i in range(2,n)
。通常的做法是什麼?
我不認爲你花費很多時間檢查甚至介紹Clojure的文章。搜索'clojure'和'looping'立即找到相關文章:https://clojuredocs.org/clojure.core/loop – schaueho
我很確定這個聲明'9'是一個素數。基本上,任何不能被'2'整除的非素數都被稱爲素數。 – resueman
@schaueho感謝您指向我的文檔鏈接。我需要閱讀更多文檔。 – Nick