# L-14 MCS 260 Fri 12 Feb 2010 : histograms # # A voting machine tallies votes. # In this second version we use a list to # tally votes and use call by reference # in this way. # tally = [0,0] # tally[0] counts no votes # tally[1] counts yes 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" if vote == 'y': t[1] += 1 elif vote == 'n': t[0] += 1 while True: v = poll() if v == '0': break update(tally,v) print 'Tally of votes :', tally