title: python3: local variable referenced before assignment
body: <p>I have a problem statement where i have to fill the missing values in
  a specified format. Like Below</p>
  <pre><code>Input1: &quot;_,_,_,24&quot; [24/4] Output1: 6,6,6,6
  Input2: &quot;40,_,_,_,60&quot;[40+60/5] Output2: 20,20,20,20,20
  Input3: &quot;80,_,_,_,_&quot;. [80/5] Output3: 16,16,16,16,16
  </code></pre>
  <p>My code is as below</p>
  <pre><code>import numpy as np
  
  
  
  def curve_smoothing(s):
      s1=s.split(&quot;,&quot;)
      s2=len(s1)
      s3=s2-1
      r=[]
      
      
      for j in s1:
          if j.isdigit():
              r.append(int(j))
          else:
              r.append(0)
      print(r)       
              
      avg=int(np.mean(r))
      
      if (r[0]==0 &amp; r[s3]!=0) | (r[0]!=0 &amp; r[s3]!=0) | (r[0]!=0 &amp; r[s3]==0):
          w=(list(map(lambda x: avg,r))) 
  
          
      return w        
    
      
      
  s=&quot;_,_,_,24&quot;    
  z=curve_smoothing(s)
  print(z)
  </code></pre>
  <p>For this I am getting UnboundLocalError: local variable 'w' referenced
  before assignment.</p>
  <p>can someone help me out rectifying it?</p>