From 94d51fb5d6c3e8b7c0581f57b06d6ac1fcb39776 Mon Sep 17 00:00:00 2001 From: renzon Date: Sun, 16 Apr 2017 12:22:58 -0300 Subject: [PATCH] =?UTF-8?q?Incluido=20doctest=20e=20c=C3=B3digo=20para=20T?= =?UTF-8?q?rem=20com=20padr=C3=A3o=20GOF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trens/README.md | 13 +++++++++++++ trens/__init__.py | 2 ++ trens/trem_gof.py | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 trens/README.md create mode 100644 trens/__init__.py create mode 100644 trens/trem_gof.py diff --git a/trens/README.md b/trens/README.md new file mode 100644 index 0000000..e083e1b --- /dev/null +++ b/trens/README.md @@ -0,0 +1,13 @@ +#Esse arquvivo documeta o comportamento de um Trem + +```python + >>> from trens.trem_gof import Trem + >>> t = Trem(4) + >>> for vagao in t: + ... print(vagao) + vagao #1 + vagao #2 + vagao #3 + vagao #4 + +``` \ No newline at end of file diff --git a/trens/__init__.py b/trens/__init__.py new file mode 100644 index 0000000..ef12d17 --- /dev/null +++ b/trens/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, unicode_literals \ No newline at end of file diff --git a/trens/trem_gof.py b/trens/trem_gof.py new file mode 100644 index 0000000..d19185f --- /dev/null +++ b/trens/trem_gof.py @@ -0,0 +1,24 @@ +class Trem: + def __init__(self, num_vagoes): + self.num_vagoes = num_vagoes + + def __iter__(self): + return IteradorTrem(self.num_vagoes) + + +class IteradorTrem: + def __init__(self, num_vagoes): + self.atual = 0 + self.ultimo_vagao = num_vagoes - 1 + + def __next__(self): + if self.atual <= self.ultimo_vagao: + self.atual += 1 + return 'vagao #%s' % (self.atual) + else: + raise StopIteration() + + +if __name__ == '__main__': + for vagao in Trem(4): + print(vagao)