0
您好我是python和編程的新手,我已經爲wordgame編寫了一些代碼,當它運行時, 有一個'None'在輸出之前打印出來。有沒有辦法刪除它們,我知道它與循環無關,但我寧願不必更改代碼很多(如果可能的話)(第一次花了足夠長的時間:)) 在此先感謝。在python的打印語句之前擺脫'NONE'
def compPlayHand(hand, wordList, n):
# Keep track of the total score
totalScore = 0
# As long as there are still usable letters left in the hand:
while compChooseWord(hand,wordList,n) is not None:
# Display the hand
print "Current Hand: ",
print displayHand(hand),
word = compChooseWord(hand,wordList,n) # comp chooses word
hand = updateHand(hand,word)
# Tell the user how many points the word earned, and the updated total score, in one line followed by a blank line
getWordScore(word,n)
totalScore += getWordScore(word,n)
# Update the hand
c = calculateHandlen(hand)
print '"'+str(word)+'"' + " earned " + str(getWordScore(word,n)) +' points.' " Total: " + str(totalScore) + " points." # Otherwise (the word is valid):
print
if compChooseWord(hand,wordList,n) is None: # End the game (break out of the loop)
print "Current Hand: ", \
displayHand(hand),
print "Total score: " + str(totalScore) + " points."
謝謝!那之後我覺得非常愚蠢。 – 2013-03-08 23:22:45
@PadraicCunningham如果這回答您的問題,請隨時通過點擊綠色選中標記將其選爲正確答案。 – askewchan 2013-03-08 23:27:26