python折磨

1.写方法没有self

class Stack:
    """
    @param: x: An integer
    @return: nothing
    """
    def __init__(self):
        zhai = []

    def push(self, x):
        # write your code here
        zhai.append(x)
    """
    @return: nothing
    """
    def pop(self):
        # write your code here
        zhai.pop(0)
    """
    @return: An integer
    """
    def top(self):
        # write your code here
        return(zhai[-1])
    """
    @return: True if the stack is empty
    """
    def isEmpty(self):
        # write your code here
        if zhai==[]:
            return True
        else:
            return False

蠢的一批,应该这样写

class Stack:
    """
    @param: x: An integer
    @return: nothing
    """
    def __init__(self):
        self.zhai = []

    def push(self, x):
        # write your code here
        self.zhai.append(x)
    """
    @return: nothing
    """
    def pop(self):
        # write your code here
        self.zhai.pop(0)
    """
    @return: An integer
    """
    def top(self):
        # write your code here
        return(self.zhai[-1])
    """
    @return: True if the stack is empty
    """
    def isEmpty(self):
        # write your code here
        if self.zhai==[]:
            return True
        else:
            return False

 

posted @ 2021-10-29 19:36  乐池  阅读(39)  评论(0)    收藏  举报