Mega Code Archive

 
Categories / Python Tutorial / List
 

Creating a histogram from a list of values

values = []   # a list of values print "Enter 10 integers:" for i in range( 10 ):    newValue = int( raw_input( "Enter integer %d: " % ( i + 1 ) ) )    values += [ newValue ] print "\nCreating a histogram from values:" print "%s %10s %10s" % ( "Element", "Value", "Histogram" ) for i in range( len( values ) ):    print "%7d %10d  %s" % ( i, values[ i ], "*" * values[ i ] )