We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0570c4b commit 8cf0feeCopy full SHA for 8cf0fee
2 files changed
trens/__init__.py
@@ -1,2 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-from __future__ import absolute_import, unicode_literals
trens/trem_seq.py
@@ -0,0 +1,17 @@
+class Trem:
+ def __init__(self, num_vagoes):
3
+ self.num_vagoes = num_vagoes
4
+
5
+ def __len__(self):
6
+ return self.num_vagoes
7
8
+ def __getitem__(self, pos):
9
+ indice = pos if pos >= 0 else self.num_vagoes + pos
10
+ if 0 <= indice < self.num_vagoes:
11
+ # indice 2 -> vagao #3
12
+ return 'vagao #%s' % (indice + 1)
13
+ raise IndexError('vagao inexistente %s' % pos)
14
15
+if __name__ == '__main__':
16
+ for vagao in Trem(4):
17
+ print(vagao)
0 commit comments