title: Python execution certain steps in a function based on input
body: <p>Currently , I have a function which includes steps that are common irrespective of the user input. But some steps need to be executed only for certain inputs. In the example below, (see if apples :  do something).</p>
  <p>What are other alternate, more optimized ways of accomplishing this , as opposed to entering a boolean input for every choice?</p>
  <p>E.g.:</p>
  <pre><code>choice = input(&quot;Select option: &quot;)
  if choice == &quot;1&quot;:
     apple = True
     test_operation(user, apple, pear=&quot;&quot;)
  elif choice == &quot;2&quot;:
     pear = True
     test_operation(user, apple=&quot;&quot;, pear=pear)
  elif choice == &quot;3&quot;:
     test_operation(user, apple=&quot;&quot;, pear=&quot;&quot;)
  
  
  def test_operation(user, apple, pear):
  
      if apple:
         do something
      if pear:
          do something else
      else:
          do both
  
      #Print results , common for all
      for category in operations:
          print(f&quot;\n{category}&quot;)
          for task in operations[category]:
               print(f&quot;{task}: {operations[category][task]}&quot;)
  </code></pre>