代码展示

  • 半成品迭代器
class myddq:
    def __init__(self,max):
        self.max=max
        self.foot=2
    def __iter__(self):
        return self
    def appare(self):
        if self.max<=1:
            return False
        else:
            if self.foot<=self.max:
                for i in range(8):
                    if self.foot%(i+2)==0 and self.foot!=i+2:
                        raise StopIteration
                self.foot+=1
                return True
    def __next__(self):
        if self.appare():
            return self.foot-1
        else:
            raise StopIteration
if __name__=="__main__":
    my=myddq(10)
    for i in my:
        print(i,end="、")

要点

恶心死了,用到时在学吧。。。