在python中的print语句之前删除'NONE'

时间:2013-03-08 23:12:20

标签: python printing output

您好我是python和编程的新手,我为wordgame写了一些代码,当它运行时, 在某些输出之前打印出“无”。有没有办法删除它们,我知道它与循环返回没有任何关系,但我宁愿不必更改代码,如果可能的话(第一次把我带走了很长时间:)) 提前谢谢。

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."

1 个答案:

答案 0 :(得分:3)

我们已经过了这个,不要print displayHand,只需单独调用它。

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: ",
        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."
相关问题