Search code examples
pythonpokerdice

simple question on dice poker in python


I'm following along a textbook example of building a dice poker game. Below is a snippet of code I don't quite understand but it does work. So in the while loop under the run method, the second condition is that the wantToPlay method in the TextInterface class must be true, correct? But when I look at the wantToPlay method, there is no boolean result i.e. whether it's true or not is not given. Can someone explain how this works?

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"

Solution

  • This returns a boolean:

    return ans[0] in "yY"
    

    Think of it as saying:

    if ans[0] in "yY":
        return True
    else:
        return False