/home_Python/note/Histo/Histo.py
|INDEX| Python.use(better)
》作業中です《
#! /usr/bin/env python # coding: utf-8 ## ---------------------------------------- ## ## (C) Copyright 2000-2010, 小粒ちゃん《監修》小泉ひよ子とタマゴ倶楽部 ## ## ---------------------------------------- """ >>> s = str(license) >>> s; len(s) 'Type license() to see the full license text' 43 >>> s; len(s)*"." 'Type license() to see the full license text' '...........................................' >>> s; len(s)*"." 'Type license() to see the full license text' '...........................................' >>> s; scale(len(s)) 'Type license() to see the full license text' '....+....1....+....2....+....3....+....4...' >>> s; scale(len(s), offset=0) 'Type license() to see the full license text' '0....+....1....+....2....+....3....+....4..' >>> histo_00() >>> histo_01() A[17]....+....1....+.. C[19]....+....1....+.... B[18]....+....1....+... E[21]....+....1....+....2. D[20]....+....1....+....2 G[23]....+....1....+....2... F[22]....+....1....+....2.. H[24]....+....1....+....2.... 164 >>> None ex_fib: #1.0.0 """ ## ---------------------------------------- def scale(n, offset=1): s = "" for e in range(1, n+1): c = "." if not e%10: c = str(e//10) elif not e%5: c = "+" s += c return s ## ---------------------------------------- from random import * def histo_00(): histo = {} for _ in range(100): n = randint(0, 9) histo[n] = histo.get(n, 0) + 1 s = 0 for k, v in histo.items(): s += v print("{0:d}[{1:2d}]{2}".format(k, v, scale(v))) print(s) def histo_01(): s = "" for e in "ABCDEFGH": s += e*(ord(e)-ord("0")) histo = {} for e in s: histo[e] = histo.get(e, 0) + 1 s = 0 for k, v in histo.items(): s += v print("{0}[{1:2d}]{2}".format(k, v, scale(v))) print(s) ## ---------------------------------------- from time import ctime from sys import argv, version def inform(): n = 60 print("="*n) print("Version: %s"%version.split("\n")[0]) print("Module : %s"%argv[0].split("/")[-1]) print("Date : %s"%ctime()) print("="*n) ## ---------------------------------------- from doctest import testmod if __name__=='__main__': inform() testmod() ## ========================================
Last updated♪2010/03/09