Reputation: 180391
Hi I am new to python and programming, I have written some code for a wordgame and when it runs, there is a 'None' printed out before some output. is there a way to remove them, I know it has to do with the loop returning nothing but I would rather not have to change the code a lot if possible(took me long enough the first time :)) Thanks in advance.
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."
Upvotes: 1
Views: 2885
Reputation: 62878
We've been over this, don't print displayHand
, just call it on its own.
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."
Upvotes: 3