Tell me what's wrong with the variable ls!



  • def min():
        for i in c2:
            a,b=srsumm(i)#summ/count
            c=a//b#average
            ls+=c#round(c,1)
        print(ls)
        return ls
    

    He says local variable 'ls referenced before assignment♪ But you don't have to announce them in advance.



  • You don't have to ream. But you have an operator. +=that is, it adds another number to the existing value. I mean, actually.

    ls += c <==> ls = ls + c
    

    It can be seen from this record that it will be taken first. lsand then changed and assigned. So the interpreter's message is absolutely correct.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2