title: How do to store variables which are strings in python and pass them around in functions?
body: <p><strong>I have a problem where i get an error message telling me its used before its assigned. I am not sure how to pass around the variable result and answer in my code. 
  The problem is that i am creating a shift cypher.</strong></p>
  
  <p>These are the instructions:</p>
  
  <p><em>Complete the encode method so that it returns the encoded message.
  Complete the decode method so that it returns the decoded message.
  In the main method, 
        - prompt the user for the message.
        - prompt the user for the shift amount.<br>
        - Print the message.<br>
        - Call encode with the message and the shift amount.<br>
        - Store the encoded message returned from encode.<br>
        - Print the encoded message.<br>
        - Send the encoded message and the shift amount to the decode method.<br>
        - Print the decoded message.</em></p>
  
  <pre><code>def encode(s, shiftamount):
    for x in range(0, len(s)):
  
      if s[x] == " ":
        print(" ", end="")
  
      if s[x] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        if chr(ord(s[x]) + shiftamount) &gt; 'Z' : 
          result += chr(ord(s[x]) + (shiftamount - 26)) 
  
        if chr(ord(s[x]) + shiftamount) &lt;= 'Z' :
          result += chr(ord(s[x]) + shiftamount)
  
      if s[x] in "abcdefghijklmnopqrstuvwxyz":
        if chr(ord(s[x]) + shiftamount) &gt; 'z' : 
          result += chr(ord(s[x]) + (shiftamount - 26)) 
  
        if chr(ord( s[x] ) + shiftamount) &lt;= 'z' :
          result += chr(ord(s[x]) + shiftamount)
    return result
  
  def decode(s, shiftamount):
  
    for y in range(0, len(s)):
  
      if s[y] == " ":
        print(" ", end="")
  
      if s[y] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        if chr(ord(s[y]) + shiftamount) &gt; 'Z' : 
          answer += chr(ord(s[y]) - (shiftamount - 26)) 
  
        if chr(ord(s[y]) + shiftamount) &lt;= 'Z' :
          answer += chr(ord(s[y]) - shiftamount)
  
      if s[y] in "abcdefghijklmnopqrstuvwxyz":
        if chr(ord(s[y]) + shiftamount) &gt; 'z' : 
          answer += chr(ord(s[y]) - (shiftamount - 26)) 
  
        if chr(ord( s[y] ) + shiftamount) &lt;= 'z' :
          answer += chr(ord(s[y]) - shiftamount)
    return answer
  
  
  def main():
    s = input("Enter the message:")
    shiftamount = int(input("Enter the shift:"))
    print(s)
    encode(s,shiftamount)
    decode(s,shiftamount)
    print(result)
    print(answer)
  
  
  ########################################################################
  ###                Do not modify anything below here                 ###
  ########################################################################
  if __name__ == '__main__':
        main()
  </code></pre>