35 lines
834 B
Python
35 lines
834 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import sys
|
||
|
|
||
|
def histogram(data):
|
||
|
height_max = max(data)
|
||
|
height_min = min(min(data), 0)
|
||
|
current_line = height_max
|
||
|
|
||
|
while current_line >= height_min:
|
||
|
to_print = ""
|
||
|
|
||
|
if current_line == 0:
|
||
|
print("-" * len(data))
|
||
|
else:
|
||
|
for elem in data:
|
||
|
if current_line > 0 and elem >= current_line:
|
||
|
to_print += "#"
|
||
|
elif current_line > 0:
|
||
|
to_print += " "
|
||
|
elif current_line < 0 and elem <= current_line:
|
||
|
to_print += "#"
|
||
|
else:
|
||
|
to_print += " "
|
||
|
print(to_print)
|
||
|
|
||
|
current_line = current_line - 1
|
||
|
|
||
|
def main():
|
||
|
args = [int(x) for x in sys.argv[1:]]
|
||
|
histogram(args)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|