-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy path1-range.py
More file actions
40 lines (35 loc) · 747 Bytes
/
1-range.py
File metadata and controls
40 lines (35 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Range:
def __init__(self, first, second=None, step=1):
if second is None:
self.start = 0
self.current = 0
self.end = first
self.step = step
else:
self.start = first
self.current = first
self.end = second
self.step = step
def __iter__(self):
return self
def __next__(self):
result = self.current
if (result >= self.end and self.step > 0
or result <= self.end and self.step < 0):
raise StopIteration
else:
self.current += self.step
return result
def print_space(str):
print("{}".format(str), end=' ')
for i in Range(10):
print_space(i)
print()
for i in Range(3, 18):
print_space(i)
print()
for i in Range(2, 15, 2):
print_space(i)
print()
for i in Range(10, 0, -1):
print_space(i)