#!/usr/bin/python3 # # This program reads a list of numbers from the standard input, with # one or more numbers per line, and prints a vertical histogram # corresponding to those numbers. In this histogram, each number N is # represented by a column of N characters "#" starting from a # base-line of N dash characters "-" representing value 0. Positive # numbers are represented by a column above zero while negative # numbers are represented with a column below zero. # def v_histogram(A): top = 0 bottom = 0 for a in A: if a > top: top = a elif a < bottom: bottom = a i = top while i > 0: for a in A: if a >= i: print('#',end='') else: print(' ',end='') print() i = i - 1 for a in A: print('-',end='') print() while i > bottom: i = i - 1 for a in A: if a <= i: print('#',end='') else: print(' ',end='') print() import sys X = [] f = open(sys.argv[1]) for l in f: for n in l.split(): X.append(int(n)) v_histogram(X)