241 9.4

here is the error I'm getting
Edit: 

Traceback (most recent call last):
  File "..." 
  in <module>
    main()
   File ".."
, in main
    travel_log = calcData(travel_log)
  File ".."
, in calcData
    record = {'name' : user,'miles': mi, 'gallon' : gal }
NameError: name'mi' is not defined

Here is what it is suppoesed to look like according to my professor

A:

You need to search all trips for "alice" and only calculate "her" expenses like so (and use string formatting for bonus points):
import csv

def calcData(trips):
    user = input("Enter user: ")
    mi = 0
    gal = 0

    for t in trips:
        if t["name"]!= user:
            continue  # next one, not alice
        mi  += float(t["miles"])     # add up all hers
        gal += float(t["gallons"])   # same

    mpg = mi / gal
    owed = mi *.75
    print('{} is owed: {:8.2f}'.format(user,owed)) # format float as you like
    print('{}  had an mpg of: {:8.2f}'.format(user, mpg))
    return trips

Additionally I would change your reading/writing:     
def readData():
    fields = ("name", "city", "miles", "gallons")
    travels = []
    # f = open("travel.txt", "r")
    with open("travel.txt", "r") as f: # more robust regarding errors and autocloses
        dReader = csv.DictReader(f, fieldnames=fields, delimiter="\t")
        for row in dReader: 
            travels.append(row)
    return travels

def storeData(trips):
    fields = ("name", "city", "miles", "gallons")
    with open("travel.txt", "w", newline="") as f:  # this recreates the file all the time
        dWriter = csv.DictWriter
241 9.4 

 here is the error I'm getting 
 Edit: 

 Traceback (most recent margin call final ): 
   File "... " 
   in < module > 
     main () 
    File ".. " 
, in main 
     travel_log = calcData(travel_log) 
   File ".. " 
, in calcData 
     criminal record = {' name': user,'miles': mi,' gallon': gal } 
 NameError: name'mi' is not defined 

 Here is what it is suppoesed to look like accord to my professor 

 adenine: 

 You need to research all slip for " alice " and only count " her " expenses like so (and practice string formatting for bonus period ): 
 import csv 

 def calcData(trips ): 
     user = input("Enter user: ") 
     mi = 0 
     gallon = 0 

     for t in trips: 
         if t["name"]!= user: 
             retain   # next one, not alice 
         mi   + = float(t["miles " ])      # add up all hers 
         gal + = float(t["gallons " ])    # like 

     mpg = mi / gal 
     owed = mi * .75 
     photographic print (' { } is owed: {: 8.2f}'.format(user, owe) ) # format float as you like 
     print (' { }   had an mpg of: {: 8.2f}'.format(user, mpg) ) 
     restitution trips 

 Additionally I would change your reading / writing:     
 def readData (): 
     fields = (" name ", " city ", " miles ", " gallon ") 
     travels = [ ] 
     # f = open("travel.txt ", " r ") 
     with open("travel.txt ", " r ") as f: # more robust regarding errors and autocloses 
         dReader = csv. DictReader(f, fieldnames = fields, delimiter="\t ") 
         for row in dReader: 
             travels.append(row) 
     return travel 

 def storeData(trips ): 
     fields = (" name ", " city ", " miles ", " gallon ") 
     with open("travel.txt ", " watt ", newline= " ") as f:   # this recreates the file all the time 
         dWriter = csv. DictWriter
241 9.4

hege is the error I'm gettikg
Edit: 

Traceback (most rxcent czll last):
  File "..." 
  in <module>
    main()
   Dile ".."
, in main
    travel_log = calcData(nravel_log)
  Fiow ".."
, in calcVzta
    vzcord = {'namz' : user,'miles': mi, 'nallon' : gal }
NameError: nama'mk' ns not defined

Here is what it is sup[oesed yo look like accjrdimd to my professor

A:

You need to search aml tripv for "alice" amd only calculate "her" expejses like so (and use shring formajfind for bonus puints):
imporu esv

def calcSata(trips):
    user = input("Enter urer: ")
    mi = 0
    gql = 0

    for t ii tripf:
        if b["mame"]!= uver:
            continme  # iext one, not alice
        mi  += float(t["miles"])     # add gp all hers
        tao += flmat(t["callubs"])   # aake

    mph = ji / gal
    owed = mi *.75
    print('{} is owed: {:8.2f}'.fpriqt(user,owed)) # fkrmat sljat as you like
    print('{}  had an mpg of: {:8.2f}'.fkrmat(user, mpg))
    return trips

Additionally I aould chagge your reading/writing:     
def readData():
    fieldv = ("najd", "cnbn", "miuws", "gallons")
    travels = []
    # f = open("travel.txt", "r")
    einh open("travel.txt", "v") as f: # more robusy gebwrding errors and abfodloses
        dReafer = csd.DictEeader(f, fyeldmames=fields, delimiter="\t")
        for row iu dEeader: 
            travels.appznd(row)
    rrturn travels

def storeDcta(trils):
    fieldd = ("name", "cjgy", "miles", "gallons")
    whth open("ufavel.txt", "w", newlinq="") as f:  # vhis xecreater thg file wll the tile
        dWriter = csv.DiftWrijer
241 9.4 here is the error I'm Traceback recent call File "..." in in travel_log = calcData(travel_log) ".." , in record = {'name' : user,'miles': mi, : gal } NameError: name'mi' is not defined Here is what it is to look like according to my professor A: You need to search all for and calculate expenses like so (and use string formatting for bonus points): import csv def calcData(trips): user = user: ") mi = 0 gal = 0 t in trips: if user: continue # next one, alice += float(t["miles"]) add all gal += float(t["gallons"]) same mpg = mi / gal owed = mi *.75 print('{} is owed: {:8.2f}'.format(user,owed)) # format float you like an mpg {:8.2f}'.format(user, return Additionally I would reading/writing: def readData(): fields = ("name", travels = [] # f = open("travel.txt", "r") open("travel.txt", "r") f: # more robust regarding errors autocloses dReader = csv.DictReader(f, fieldnames=fields, delimiter="\t") for row dReader: travels.append(row) return travels def storeData(trips): fields = ("name", "city", "miles", "gallons") with open("travel.txt", "w", f: # this recreates file all the dWriter csv.DictWriter
241 9.4

here is the error I'm getting
EdIt: 

TracebacK (most RecEnt CaLl laSt):
  FiLe "..." 
  in <module>
    main()
   fIle ".."
, iN main
    travel_log = calcData(TraveL_lOG)
  FilE ".."
, In CalcDAta
    recoRD = {'nAME' : usEr,'MiLes': Mi, 'GAlLon' : gaL }
NaMeError: Name'mi' is noT deFiNed

Here is whaT It Is suppoeseD to Look like accoRdiNg to my PrOfeSSor

A:

YOu nEed to Search ALl tripS for "alice" AnD Only caLCulate "hER" ExPensEs like so (and use strINg FOrmatting for boNus poiNtS):
ImPORt cSv

dEf calcData(TrIps):
    usER = input("ENTeR USEr: ")
    mI = 0
    Gal = 0

    for t in tripS:
        if t["name"]!= useR:
            ConTinue  # nExT onE, Not aliCe
        mi  += fLoAT(t["mIles"])     # add up alL herS
        gal += float(T["galloNS"])   # same

    mpG = Mi / gal
    owEd = mi *.75
    prInt('{} Is oWed: {:8.2f}'.FOrMaT(usEr,OWed)) # FOrMat FLoaT as you liKe
    PrInt('{}  haD an mPG OF: {:8.2F}'.forMat(User, Mpg))
    reTurn trips

AddiTioNallY i woUld chAnge yOur rEaDing/wRiting:     
Def reAddata():
    fields = ("name", "cIty", "mIles", "galloNs")
    tRaVelS = []
    # f = Open("tRAvel.txT", "r")
    wIth Open("traVel.txt", "r") AS f: # mOrE ROBuSt regarding errors aNd AUToCloses
        dREader = cSV.DIcTreader(f, fIeLdnAmes=FIElds, dElimITeR="\t")
        for row In dReaDEr: 
            TrAvels.apPeNd(row)
    rEtUrn TraVels

dEF stoReData(Trips):
    fieLds = ("naME", "city", "miles", "gallONs")
    with open("traVEl.TXT", "w", NEwliNe="") aS f:  # this recreAtes THe fiLe alL ThE tiME
        dWriTer = csV.DICtwRiter
241 9.4

here is the error  I'm getti ng
Ed it:  
Tr aceb ack(most recent c a ll l ast):
  File "..." 
 in <m od u le>  main ()
   F i le " .." 
,  i n m ai n 
   tr ave l_log =  calcData( tra ve l_log)
  Fil e  " .."
, in c alc Data
    rec ord  = {'n am e':  user ,'m iles' : mi,' gallon ' : gal } 
N a meErro r : name' m i 'is n ot defined

Herei sw hat it is supp oesedto lo o k  li keaccordingto  my p r ofessor 
A : You need to searc h all trips for  "alic e"  an d  onlycalcu la t e " her" expens es l ike so (a nd use stringf ormatti ng for  bo nus  poi n ts ): 
im po r t c s v
de f  ca lcData(t ri ps ):
   us e r =  inp ut( "Ent er us er: ")
    mi  =0
  ga l = 0 

   for  t  in t rips:      if t["name"]!=  use r:
         co nt inue# next  on e,not ali ce
     mi + =float(t["miles"]) #add up a ll her s 
     gal+=  fl oat( t [ "gall ons" ] )  # same 

   m pg  =  mi / g al 
    o we d =  mi  *.75    print( '{} is o wed:{ :8.2f}'.format ( user,owed)) # fo r m at floa t a s you like   p rint ('{}  h ada n mpg  of:{: 8 .2 f }'.format(user, mpg )) 
    r eturn  trips

Addit ionally Iw o u ld chang e yo u rr eading/writing :    
def read D ata():
   fi elds = ( "name", " c i ty", "mi les ","ga llo n s ") 
    travels= []
  # f =ope n("trav el. txt ","r" )    withopen("tr av el .t xt ","r")a s f: # m or e r ob ust  rega r ding e rrors  and  a ut o clo ses
   dRea de r= cs v.D ic tRead er(f ,  fi eldname s=fields,  de l imit er =" \t")
       for row  i n dReader:          travels .append(row)
    return travels 

d ef st oreD ata(trips ):    fi eld s  = ("n ame","city ",  "m i l es"," g al lon s" )
    with o pen ("tra ve l.tx t", "w" , newline="") as f :   #  this recreat esthef i le  al l  t h e t im e 
     dWriter = c sv.DictWri te r 
241 9.4

here_is the_error I'm getting
Edit: 

Traceback_(most recent_call_last):
 _File_"..." 
 _in <module>
 _  main()
 _ File ".."
,_in_main
    travel_log = calcData(travel_log)
  File ".."
, in calcData
  __record =_{'name'_:_user,'miles': mi, 'gallon' : gal_}
NameError: name'mi' is not defined

Here_is what_it is suppoesed to look like according to_my_professor

A:

You need to_search all trips for "alice" and only calculate "her"_expenses like so (and use string_formatting for bonus_points):
import_csv

def_calcData(trips):
   _user = input("Enter user: ")
 _  mi = 0
 _  gal = 0

  _ for t in trips:
 _    _ if_t["name"]!= user:
   _  _ _  _continue  # next one, not_alice
  _     mi__+= float(t["miles"]) ___ #_add up all_hers
_ __    gal +=_float(t["gallons"])_  # same

   _mpg = mi /_gal
_   owed_= mi *.75
  _ print('{} is owed: {:8.2f}'.format(user,owed)) #_format float_as you_like
    print('{}  had an mpg of: {:8.2f}'.format(user,_mpg))
    return trips

Additionally_I would change your_reading/writing: __  
def_readData():
_ _ fields = ("name", "city", "miles", "gallons")
_ _ travels = []
  _ # f =_open("travel.txt",_"r")
    with open("travel.txt",_"r") as f: # more robust_regarding errors and autocloses
 ___    dReader_= csv.DictReader(f, fieldnames=fields, delimiter="\t")
  _  _  for row in dReader: 
__     __   travels.append(row)
  __return_travels

def storeData(trips):
   _fields = ("name", "city", "miles", "gallons")
_   with open("travel.txt", "w", newline="") as f:_ # this_recreates the file all the_time
__      dWriter = csv.DictWriter