# L-14 MCS 260 12 Feb 2010 : histograms # # A voting machine tallies votes. # We use two global variables in the main loop # as arguments in a sequence. # tno = 0 # tno counts no votes tyes = 0 # tyes 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': return (t[0],t[1]+1) elif vote == 'n': return (t[0]+1,t[1]) while True: v = poll() if v == '0': break (tno,tyes) = update((tno,tyes),v) print 'Tally of votes :', (tno,tyes)