# L-14 MCS 260 28 Sep 2007 histograms # # A voting machine tallies votes. # tally = [0,0] # tally[0] counts yes votes # tally[1] counts no votes def poll(): "asks whether approve or not" print 'Vote yes or no, 0 to stop' answer = raw_input('approve ? (y/n) ') return answer def update(t,vote): "updates tally t with vote" nt = t if vote == 'y': nt[0] += 1 elif vote == 'n': nt[1] += 1 return nt while True: v = poll() if v == '0': break tally = update(tally,v) print 'Tally of votes :', tally