AttributeError: 'JugPuzzle' object has no attribute 'current'

113 Views Asked by At
class Jug:
    def __init__(self, current, highest):
        self.current = current
        self.highest = highest

    def spill(self, jug, jug_1):
        """
        :return: The new values of the jug spilled from and the jug spilled to
        """
        while True:
            self.current[jug] -= 1
            self.current[jug_1] += 1
            if self.current[jug] == 0 or self.current[jug_1] == self.highest[jug_1]:
                break


    def __str__(self):
        """
        :return: The new values of all the jugs
        """
        return "Jug 0: {0}/8 Jug 1: {1}/5 Jug 2: {2}/3".format(self.current[0], self.current[1], self.current[2])


class JugPuzzle:

    def __init__(self):
        self.jugs = [[8, 8], [0, 5], [0, 3]]  # [jug0[0], jug1[0], jug2[0]]
        self.turn = 0

    def calculate(self):
        jug_from = int(input("\nEnter jug to spill from: "))

        if self.jugs[jug_from][0] == 0:
            print("Cannot spill from an empty Jug. Try again")
        else:
            jug_to = int(input("Enter jug to spill to: "))
            if self.jugs[jug_to][0] == self.jugs[jug_to][1]:
                return "Cannot spill into a full Jug"
            else:
                Jug.spill(my_jug, jug_from, jug_to)  # --> Is this call correct?



if __name__ == "__main__":
    jug0 = [8, 8]
    jug1 = [0, 5]
    jug2 = [0, 3]
    jugs = [jug0, jug1, jug2]
    my_jug = Jug([jug0[0], jug1[0], jug2[0]], [jug0[1], jug1[1], jug2[1]])
    (my_jug.spill(0, 1))
    print(my_jug.__str__())

    my_jug = JugPuzzle()
    print(my_jug.calculate())

The spill method in the Jug class works, however, when I call the spill method from the calculate method in the JugPuzzle class, it says JugPuzzle has no attribute current. Am I calling it incorrectly or something?

0

There are 0 best solutions below