【发布时间】:2011-03-29 23:29:58
【问题描述】:
我正在学习构建骰子扑克游戏的教科书示例。下面是一段我不太明白的代码,但它确实有效。那么在run方法下的while循环中,第二个条件就是TextInterface类中的wantToPlay方法必须为真,对吗?但是当我查看 wantToPlay 方法时,没有布尔结果,即没有给出它是否为真。有人可以解释这是如何工作的吗?
class PokerApp:
def run(self):
while self.money >= 10 and self.interface.wantToPlay():
self.playRound()
class TextInterface:
def wantToPlay(self):
ans = input("do you wish to try your luck? ")
return ans[0] in "yY"
【问题讨论】: