不幸的是,raw_input沒有按照我的需要去做。我想要做的是得到totPrimes =無論我在提示中輸入什麼。如果我將while count < totPrimes
替換爲while count < 50
此腳本有效。如果我在提示符中鍵入50,這個腳本不起作用,我害怕raw_input不是我想要使用的函數嗎?這裏是我的代碼片段:Python:raw_input讀取數字時出現問題
testNum = 3
div = 2
count = 1
totPrimes = raw_input("Please enter the primes: ")
while count < totPrimes :
while div <= testNum :
考慮將標題更改爲更充分的標題。 p.e.'problem with raw_input reading a number',或類似的問題。 – joaquin 2011-04-23 07:52:27
僅供參考,這是Python 2.x中的一個問題,因爲您可以比較不同類型的對象。在Python 3.x中它會引發一個'TypeError:unorderable types'。 – katrielalex 2011-04-23 08:57:03