title: Why two variables(num1,num2) are not defined in the if statement
body: <p>Thanks to those helpful people yesterday who solved the try-catch error!<br />
  However, another error occurred. After the user_option not defined error is solved, when the user inputs an invalid option (like <code>list index out of range</code> error), the python program outputs another error while dealing with the list index out of range: <code>print(&quot;The divide is&quot;, num1, &quot;/&quot;, num2, dividing(num1, num2)) NameError: name 'num1' is not defined</code><br />
  The codes are the following:</p>
  <pre><code>if user_input == 0:
      user_option = None
      try:
          small_option = int(
          input(&quot;Which operation do you want to do? \n 1. Adding \n 2. Subtracting \n 3. Multiplying &quot;
                    &quot;\n 4. Dividing&quot;))
          small_list = [0, 1, 2, 3]
          user_option = small_list[small_option-1]
       except IndexError:
           print(&quot;Invalid option&quot;)
           if user_option == 0:
               num1 = float(input(&quot;Enter first number: &quot;))
               num2 = float(input(&quot;Enter second number: &quot;))
           if user_option == 1:
               print(&quot;The sum is&quot;, num1, &quot;+&quot;, num2, adding(num1, num2))
           elif user_option == 2:
               print(&quot;The subtraction is&quot;, num1, &quot;-&quot;, num2, substract(num1, num2))
           elif user_option == 3:
               print(&quot;The multiplying is&quot;, num1, &quot;*&quot;, num2, multiplying(num1, num2))
           else:
               print(&quot;The divide is&quot;, num1, &quot;/&quot;, num2, dividing(num1, num2))
               break
  </code></pre>
  <p>This is the whole codes in the while loop for the calculator<br />
  Only the num1 and num2 in the add function went undefined.</p>