nick34992
2/12/2017 - 10:11 PM

Python Square Root Iterator

Python Square Root Iterator

#!/usr/bin/env python3.5

class Squared:
    def __init__(self):
        self.number = 0
    def __iter__(self):
        return self
    def __next__(self):
        self.number += 1
        return self.number * self.number
 
if __name__ == '__main__':
    squared = Squared()
    count = 0
    for number in squared:
        print(number)
        if count > 5:
            break
        count += 1