-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber-printer.py
executable file
·59 lines (48 loc) · 1.38 KB
/
number-printer.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import argparse
import random
def parse_arguments():
parser = argparse.ArgumentParser(description="Generate a range of random integers")
parser.add_argument(
"-o",
"--ordered",
action="store_true",
dest="ordered",
help="Returns an ordered range",
)
parser.add_argument(
"-s",
"--start",
action="store",
dest="start",
type=int,
default=1,
help="Specify the start of the range",
)
parser.add_argument(
"ammount",
action="store",
type=int,
default=10,
nargs="?",
help="Specify the ammount of digits to return",
)
args = parser.parse_args()
if args.ammount < 0:
parser.error(f"argument ammount: must be a positive integer: '{args.ammount}'")
return args
def main():
args = parse_arguments()
start = args.start
end = args.start + args.ammount
result = []
number_list = list(range(start, end))
if not args.ordered:
random.shuffle(number_list)
## Map might be used, as it's generally more efficient, although in this case, a for loop is clearer
## and we don't take advantage of many of the more interesting properties of the map function.
# list(map(print, number_list))
for n in number_list:
print(n)
if __name__ == "__main__":
main()