3 Show seats lost by democrats
4 Author: Bryan Steinbach
15 conn
= sqlite3
.connect(tablefn
)
17 def retrieve_state(state
):
19 c
.execute('''select polls.gop,polls.dem,polls.ind,names.incpar
20 from polls,names where polls.state = '%s' and names.state = '%s' order by polls.date1 desc limit 1'''%(state
,state
))
22 gopfrac
,demfrac
,indfrac
,incpar
= c
.next()
26 fracs
= np
.array([gopfrac
,demfrac
,indfrac
])
27 partys
= ['Republican','Democrat','Independent']
29 favi
= np
.argmax(fracs
)
36 c
.execute(''' select distinct state from polls ''')
38 for s
in c
: states
.append(s
[0])
45 incpars
,newpars
= [],[]
47 incpar
, newpar
= retrieve_state(state
)
49 incpars
.append(incpar
)
50 newpars
.append(newpar
)
52 def countseats(parties
):
58 if p
== 'Republican': gop
+= 1
59 elif p
== 'Democrat': dem
+= 1
60 elif p
== 'Independent': ind
+= 1
62 print "Unknown party: ",p
66 gop0
,dem0
,ind0
= countseats(incpars
)
67 gop1
,dem1
,ind1
= countseats(newpars
)
69 lost_seats
= dem0
-dem1
71 print "Seats lost by democrats: ",lost_seats