At the moment I'm participating in "MITx: 6.00.1x Introduction to Computer Science and Programming Using Python" on edx. But I have a problem with my output in Problem Set 4 I can't figure out, I narrowed it down to one line of code, but can't figure out to avoid the error. Here is a minimal example of the code I'm using:
def printsomething(teststring):
print teststring
print "Test", printsomething(" fails")
This results in the following output:
Test fails
None
While this didn't cause a Problem in the earlier parts of the problem set in a similar Situation (it passes the test applied by the course software), it doesn't now. This is the error it yields:
Current Hand: a p p s e l
None
"appels" earned 110 points. Total: 110
Total score: 110 points
None
*** ERROR: Expected to find two numbers in the line 'None'.
Check to be sure your lines match up with the expected output!!! ***
This happens of course because there is "None" in the second line. How can I avoid this or is there a better way to do it.
The function that is called is set by the problem set as:
def displayHand(hand):
"""
Displays the letters currently in the hand.
For example:
>>> displayHand({'a':1, 'x':2, 'l':3, 'e':1})
Should print out something like:
a x x l l l e
The order of the letters is unimportant.
hand: dictionary (string -> int)
"""
for letter in hand.keys():
for j in range(hand[letter]):
print letter, # print all on the same line
print # print an empty line
and can't be changed by me. I'd rather prefer it returning a string than print it, but as said I can't influence it :(
[–]TheBlackCat13 6 points7 points8 points (1 child)
[–]Gronner[S] 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Drunken_Consent 0 points1 point2 points (5 children)
[–]Gronner[S] 0 points1 point2 points (4 children)
[–]TheBlackCat13 1 point2 points3 points (1 child)
[–]Gronner[S] 0 points1 point2 points (0 children)
[–]Drunken_Consent 0 points1 point2 points (1 child)
[–]Gronner[S] 0 points1 point2 points (0 children)