Question: I have this code for the Was Clinton Right python programming challenge, and I keep getting these errors. I ' m not sure what to
I have this code for the Was Clinton Right python programming challenge, and I keep getting these errors. Im not sure what to do to fix them. An example of the working code to compare with and use to figure out what's wrong would be perfect.
import csv
import math
def parsepresidentfile:
president
parties
for line in file:
line line.strip
tmplist line.split
partiestmplist tmplist
slices tmplist:
for i in slices:
presidentinti tmplist
return president, parties
def parsedatafile:
data
linenum
for line in file:
if linenum :
line line.strip
tmplist line.split
data.appendtmplist
linenum
return data
def gettotalsdata presidents:
output
preoutput
for i in data:
i inti
try:
preoutputpresidentsiappendi
preoutputpresidentsiextendi:
except KeyError:
preoutputpresidentsi
preoutputpresidentsiextendi:
for i in preoutput:
k preoutputi
tmplisti
before intk
total
for j in k:
if j :
continue
j intj
total j before
before j
tmplist.appendtotal
output.appendtmplist
return output
def printoutputoutputparties:
reptotal
demtotal
printRepublicans:
for i in output:
if partiesi "Republican":
reptotal i
if i:
printi: absroundi 'Million created jobs'
else:
printi:absroundi 'Millon lost jobs'
print
Total jobs created:", absrounddemtotal "Million jobs"
print
printThe numbers overall are accurate but the individual numbers are off because of termsending too soon."
printThis data show that while president clinton's numbers were off, his point still stands."
def main:
with openpresidentstxtr as presidentfile:
presidentfile openpresidentstxtr
datafile openBLSprivate.csvr
presidents, parties parsepresidentpresidentfile
data parsedatadatafile
output gettotalsdata presidents
printoutputoutputparties
presidentfile.close
datafile.close
main
These are the error messages I keep getting.
LAST RUN on :: PM
Traceback most recent call last:
File homecodioworkspacefactcheck.py line in gettotals
preoutputpresidentsiappendi
KeyError:
During handling of the above exception, another exception occurred:
Traceback most recent call last:
File guidessecurefactcheckgrader.py line in
main
File guidessecurefactcheckgrader.py line in main
factcheck importfactcheckprogram
File guidessecurefactcheckgrader.py line in importfactcheck
return importlib.importmodulepackagename
File usrlibpythonimportlibinitpy line in importmodule
return bootstrap.gcdimportnamelevel: package, level
File line in gcdimport
File line in findandload
File line in findandloadunlocked
File line in loadunlocked
File line in execmodule
File line in callwithframesremoved
File homecodioworkspacefactcheck.py line in
main
File homecodioworkspacefactcheck.py line in main
output gettotalsdata presidents
File homecodioworkspacefactcheck.py line in gettotals
preoutputpresidentsi
KeyError:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
