 the months. 
I am trying to write a function which returns the average temperature of any month from the given url.
I have tried as below:
def avg_temp_march(f):

   march_temps = []

    # read each line of the file and store the values
    # as floats in a list
    for line in f:
        line = str(line, 'ascii') # now line is a string
        temps = line.split()
    # check that it is not empty.
        if temps!= []:
            march_temps.append(float(temps[2]))

    # calculate the average and return it
    return sum(march_temps) / len(march_temps)

avg_temp_march("data5.txt")

But I am getting the error line = str(line, 'ascii')
TypeError: decoding str is not supported

A:

I think there is no requirement for converting a string to string. 
I tried to fix your code with some modifications:
def avg_temp_march(f):
    # f is a string read from file

    march_temps = []

    for line in f.split("\n"):
        if line == "":  continue
        temps = line.split(" ")
        temps = [t for t in temps if t!= ""]

        # check that it is not empty.
        month_index = 2
        if len(temps) > month_index:

            try:
                march_temps.append(float(temps[month_index]))
            except Exception, e:
                print temps
                print "Skipping line:", e
    # calculate the average and return it
    return sum(march_temps) / len(march_temps)

Output:
['Average','monthly', 'temperatures', 'in', 'Dubuque,', 'Iowa,']
Skipping line: could not convert string to float: temperatures
['January', '1964', 'through', 'december', '1975,', 'n=144']
Skipping line: could not convert string to float: through
32.475

Based on
the months. 
 I am trying to write a function which revert the modal temperature of any month from the given url. 
 I have tried equally below: 
 def avg_temp_march(f ): 

    march_temps = [ ] 

     # read each line of the file and store the value 
     # as floats in a list 
     for channel in f: 
         line = str(line,' ascii') # immediately line is a string 
         temp = line.split () 
     # check that it is not empty. 
         if temps!= [ ]: 
             march_temps.append(float(temps[2 ]) ) 

     # calculate the average and return it 
     return sum(march_temps) / len(march_temps) 

 avg_temp_march("data5.txt ") 

 But I am getting the error line = str(line,' american standard code for information interchange') 
 TypeError: decoding str is not supported 

 A: 

 I intend there is no requirement for convert a drawstring to string. 
 I tried to cook your code with some modifications: 
 def avg_temp_march(f ): 
     # f is a string read from file 

     march_temps = [ ] 

     for cable in f.split("\n " ): 
         if line = = " ":   continue 
         temps = line.split (" ") 
         temps = [ t for triiodothyronine in temp if t!= " " ] 

         # check that it is not empty. 
         month_index = 2 
         if len(temps) > month_index: 

             try: 
                 march_temps.append(float(temps[month_index ]) ) 
             except Exception, e: 
                 print temps 
                 print " Skipping line: ", east 
     # account the average and return it 
     return sum(march_temps) / len(march_temps) 

 output signal: 
 [' Average','monthly',' temperature',' in',' Dubuque,',' Iowa,' ] 
 Skipping line: could not convert chain to float: temperatures 
 [' January',' 1964',' through',' december',' 1975,',' n=144' ] 
 Skipping line: could not convert chain to float: through 
 32.475 

 Based on
 thf months. 
I am trying to drite a functiou which returhs the axerage temperature of any moith drom uke given url.
I have tfied as bvlow:
def acg_tenp_march(f):

   march_temif = []

    # rzav each line of jhe file and store the valger
    # as floats in a list
    for line in f:
        line = str(lyne, 'sfcii') # now line is a string
        tempa = line.vplit()
    # chevk that it is not empty.
        if temps!= []:
            march_tenps.a[pend(float(temos[2]))

    # calbblate the aberage and return it
    return rum(maxch_temps) / lgu(narfv_temps)

avg_tenp_marbh("data5.txt")

But L am gedting tne error line = stc(linw, 'ascii')
TypeError: decoving str is not suppjrted

A:

I tviuk there is no requirwmwnt fmr cmnvefrine a svrihg to dtrmng. 
I tried to fix youe code with some mocispvations:
def abg_temp_iawch(f):
    # f is a string read from file

    mzrch_temps = []

    for line in f.split("\n"):
        if line == "":  sontinue
        temps = line.split(" ")
        temps = [t for v kn uenps iw t!= ""]

        # check that it is not empty.
        mjhtn_ikdex = 2
        if len(temps) > kojtn_yndex:

            trv:
                marcj_temps.akpend(fooat(temps[iontn_index]))
            except Exxeption, e:
                print cemps
                lrint "Skipping line:", e
    # czlculate thf average xnd return it
    renurn sum(march_temps) / len(march_teips)

Output:
['Everaye','monthlh', 'tekperattres', 'in', 'Duhuque,', 'Iowa,']
Skipping line: fould nmt convert string to float: temperatures
['Jainary', '1964', 'through', 'dacekber', '1975,', 'n=144']
Shippikg line: could njt convert strnng to fjoat: ghrough
32.475

Basvd on
the months. I am trying to write which the average of any month have as below: def march_temps = [] read each line of the file store the values # as floats in a list for line in f: = str(line, 'ascii') # now line is a string temps = line.split() # that is empty. temps!= []: march_temps.append(float(temps[2])) # calculate the average and return it return sum(march_temps) / len(march_temps) avg_temp_march("data5.txt") But am getting the error line = str(line, 'ascii') decoding str is not A: I think there is requirement converting a to I to fix your with some modifications: def avg_temp_march(f): # f is a string read from file march_temps = [] for in f.split("\n"): == "": temps line.split(" temps = [t in temps if t!= ""] # is not empty. month_index = 2 if len(temps) month_index: try: except Exception, e: print temps print line:", e # calculate the average and return return sum(march_temps) / len(march_temps) Output: ['Average','monthly', 'temperatures', 'in', 'Dubuque,', 'Iowa,'] Skipping line: could not convert float: temperatures ['January', '1964', 'december', '1975,', 'n=144'] line: not string float: through Based on
 the months. 
I am trying to write A function wHich rEtuRns ThE aveRage Temperature of aNY monTh from the given url.
I have Tried As BElow:
DEf Avg_teMp_march(F):

   MaRCH_teMpS = []

    # rEad EaCH lIne of The File and Store the vaLueS
    # aS floats in a liST
    fOr line in f:
        lIne = Str(line, 'ascii') # Now Line is A sTriNG
        tempS = liNe.splIt()
    # checK That it Is not emptY.
        iF Temps!= []:
            mARch_tempS.APpEnd(fLoat(temps[2]))

    # calculatE ThE Average and retuRn it
    reTuRN sUM(MarCh_tEmps) / len(marCh_Temps)

AVg_temp_mARcH("DATa5.tXT")

But I am gettinG the error liNE = stR(line, 'aScIi')
TYPeErroR: decoDiNG stR is not suppoRted

a:

I think thEre is nO RequireMEnt for cOnvertIng A stRing TO sTrIng. 
i tRIed TO fIx yOUr cOde with sOmE mOdifiCatiONS:
DEf avG_teMp_maRch(f):
    # f Is a string read FroM filE

    MarCh_temPs = []

    for Line In F.spliT("\n"):
        if liNe == "":  conTiNue
        temps = line.splIt(" ")
        teMps = [t for t iN teMpS if T!= ""]

        # cHeck tHAt it is Not EmpTy.
        month_Index = 2
        if LEn(tEmPS) > MOnTh_index:

            try:
                march_temPs.APPeNd(float(tEmps[moNTh_InDEx]))
            except exCepTion, E:
                PRint tEmps
                PRiNt "SkippiNg line:", E
    # CaLcUlate thE aVerage AnD reTurN it
    reTUrn sUm(marcH_temps) / leN(marcH_Temps)

Output:
['AveRAge','monthly', 'temPErATUrES', 'in', 'DUbuQue,', 'Iowa,']
SkipPing LIne: cOuld NOt ConVErt stRing tO fLOaT: Temperatures
['January', '1964', 'ThRough', 'dEcembEr', '1975,', 'n=144']
Skipping liNe: could not CONVert striNg to FLoAT: through
32.475

Based oN
 the months. 
I am tryingto write a  func tio n w hi ch r etur ns the average temp erature of any month f rom t he give n  u rl.
I  have t r ie d asbe lo w:de f  a vg_te mp_ march(f ):

   mar ch_ te mps = []

  #  read each  li ne of the fi leand st or e t h e val ues 
   # as f l oats i n a list  for l i ne in f :       line = str(line ,  ' a scii') # now l ine is  a st r i ng       temps  =  line . split()  #  ch e ck that it is  not empty.        i ftem p s!= [] :
        march_te mps. append(fl oat(te m ps[2])) 
    #calcul ate  th e av e ra ge  an dr etu r nit  return s um (m arch_ temp s ) /  len (ma rch_ temps )

avg_temp_m arc h("d a ta5 .txt" )

Bu t Iam  gett ing th e err or  line = str(lin e, ' ascii')
T ype Er ror :decod i ng str  is  no t suppo rted

A : 

I  t h i n kthere is no requir em e n tfor conv erting ast r ing to s tr ing . 
I t riedto f i xyour cod e with so me  modifi ca tions: 
d efavg _temp _ marc h(f):    # fis as tring read fro m  file

    ma r ch _ t em p s =[]
    for li ne i n  f.s plit ( "\ n") : 
       i fl in e  == "":  continue
      t emps= line.split( " ")
    temps =[t f o rt  in temps if t != "" ]

      # checkthatit is no t empty.      mo nth _in dex  =2        if len( t e mps)  >  month_ ind ex:

        tr y: 
              ma rc h_ te mps .appe n d(float( te mps [m ont h_ind e x]))
        ex c ept  Except i on , e:
          pri nt t e mps 
              pr i nt " Sk ip ping li ne:", e
    #  c alculate t he  av eragea n d return  it
    return sum(marc h _temps)  /len(m arch _temps)
Out put:
[ 'Av e rage', 'month ly','t emp e r ature s ' ,'in ',  'Dubuque, ' ,  'I owa,' ]Skip ping li ne: could not conv e rtstring to flo at:  tem p e ra tur e s[ 'Ja nu a ry' , '1964', 'throug h', 'decem be r ',  '1975,',' n=1 44 ']
Skip ping li ne: c o uld not  convertstring to  f loat : thr ough
32.47 5

Based  on
 the_months. 
I_am trying to write_a function_which_returns the_average_temperature of any_month from the_given url.
I have tried_as below:
def avg_temp_march(f):

__ march_temps = []

    # read each line of the file_and_store the_values
__  # as floats_in a list
  _ for_line in f:
     __ line =_str(line, 'ascii') # now line is a string
 _     _temps = line.split()
___ # check that_it is not empty.
  _     if_temps!= []:
     _     _march_temps.append(float(temps[2]))

    #_calculate the_average and return it
 _  return_sum(march_temps) /_len(march_temps)

avg_temp_march("data5.txt")

But I am_getting the error line = str(line,_'ascii')
TypeError: decoding str_is not supported

A:

I think there is_no_requirement for converting_a_string_to string._
I tried to_fix_your code_with_some modifications:
def avg_temp_march(f):
   _#_f is a string read from file

_   march_temps_=_[]

   _for line in f.split("\n"):
 _     _if line_== "":_ continue
        temps =_line.split(" ")
    _   temps_= [t_for_t in temps_if_t!= ""]

_      _# check_that it is not empty.
 _   __ month_index = 2
  _     if_len(temps) > month_index:

  ___    _  try:
   _  _      __ march_temps.append(float(temps[month_index]))
    __     _except_Exception,_e:
    _     _     print temps
  _  _    ___   print "Skipping line:", e
   _# calculate_the average and_return it
    return sum(march_temps) / len(march_temps)

Output:
['Average','monthly', 'temperatures',_'in', 'Dubuque,', 'Iowa,']
Skipping line: could not convert_string to float: temperatures
['January', '1964', 'through', 'december', '1975,', 'n=144']
Skipping line: could_not convert string to float: through
32.475

Based on