title: Trying to call a function outside of an if statement
body: <p>I'm doing some Python exercises and I came across a frustrating error:</p>
  
  <pre><code>line 18, in &lt;module&gt;
      modulo()
  
  NameError: name 'modulo' is not defined
  </code></pre>
  
  <p>Code is below:</p>
  
  <pre><code>number = input("Please enter a number: ")
  
  if number.isdigit():
      def modulo():
          answer = int(number) % 2
  
          if answer == 0:
              print("Your number, " + number + " is even.")
          elif answer &gt; 0:
              print("Your number, " + number + " is odd.")
          else:
              print("Error. Please try again.")
  
  else:
      print("Please try again")
  
  modulo()
  </code></pre>