2024-04-25 19:53:20 发布
网友
我的代码:
hand = {'e': 1, 'i': 2, 'h': 1, 's': 1, 'r': 1, 'w': 1, 'v': 2} def showhand(a): for letter in hand: for j in range(hand[letter]): print letter,
我希望得到的输出是:
但我看到的是:
e i i h s r w v v None
我不知道None值来自何处。如何获得我想要的输出?在
None
您必须这样调用函数:
print showhand(...)
这样做会导致Python打印showhand的返回值,即None。在
showhand
要解决您的问题,请删除print并按如下方式调用函数:
print
您必须这样调用函数:
这样做会导致Python打印
showhand
的返回值,即None
。在要解决您的问题,请删除
^{pr2}$print
并按如下方式调用函数:相关问题 更多 >
编程相关推荐