title: Python Problem: Unable to access option in program
body: <p>I keep recieving an TypeError: cannot unpack non-iterable int object when I select option 4 in the menu. How do I fix this, I have tried for hours with no success. Code is below:</p>
  <pre><code>from turtle import right
  def selection_sort(altered_number_list, sorting_order):
      if sorting_order == 1:
          for value in range (0, len(altered_number_list)-1):
              least_value = value
              for index in range (value+1, len(altered_number_list)):
                  if altered_number_list[index] &lt; altered_number_list[least_value]:
                      altered_number_list[index], altered_number_list[least_value] = altered_number_list[least_value], altered_number_list[index]           
          return altered_number_list
      else: 
          for value in range (0, len(altered_number_list)-1):
              least_value = value
              for index in range (value+1, len(altered_number_list)):
                  if altered_number_list[index] &gt; altered_number_list[least_value]:
                      altered_number_list[index], altered_number_list[least_value] = altered_number_list[least_value], altered_number_list[index]
              return altered_number_list
  def bubble_sort(altered_number_list, sorting_order):
      if sorting_order == 1:
          for value in range (len(altered_number_list)):
              for index in range (0, len(altered_number_list)-1):
                  if altered_number_list[index] &gt; altered_number_list[index+1]:
                      altered_number_list[index], altered_number_list[index+1] = altered_number_list[index+1], altered_number_list[index]
          return altered_number_list
      else: 
          for value in range (len(altered_number_list)):
              for index in range (0, len(altered_number_list)-1):
                  if altered_number_list[index] &lt; altered_number_list[index+1]:
                      altered_number_list[index], altered_number_list[index+1] = altered_number_list[index+1], altered_number_list[index]
          return altered_number_list
  
  def insertion_sort(altered_number_list, sorting_order):
      if sorting_order == 1:
          for value in range(1, len(altered_number_list)):
              insert_value = number_list[value]
              data_switch = value
              while data_switch &gt; 0 and altered_number_list[data_switch-1] &gt; insert_value:
                  altered_number_list[data_switch] = altered_number_list[data_switch-1]
                  data_switch -= 1
              altered_number_list[data_switch] = insert_value
          return altered_number_list
      else: 
          for value in range(1, len(altered_number_list)):
              insert_value = number_list[value]
              data_switch = value
              while data_switch &gt; 0 and altered_number_list[data_switch-1] &lt; insert_value:
                  altered_number_list[data_switch] = altered_number_list[data_switch-1]
                  data_switch -= 1
              altered_number_list[data_switch] = insert_value
          return altered_number_list
  
  def quick_sort(altered_number_list, number_list_min, number_list_max, sorting_order):
      if number_list_min &lt; number_list_max:
          split_value = partition_sort(altered_number_list, number_list_min, number_list_max, sorting_order)
          quick_sort(altered_number_list, number_list_min, split_value-1, sorting_order)
          quick_sort(altered_number_list, split_value+1, number_list_max, sorting_order)
  
  def partition_sort(alter_number_list, number_list_min, number_list_max, sorting_order):
      if sorting_order == 1:
          pivot_value = alter_number_list[number_list_min]
          left_value = number_list_min + 1
          right_value = number_list_max
          complete = False
          while not complete:
              while left_value &lt;= right_value and alter_number_list[left_value] &lt;= pivot_value:
                  left_value = left_value + 1
              while alter_number_list[right_value] &gt;= pivot_value and right_value &gt;= left_value:
                  right_value = right_value - 1
              if right_value &lt; left_value:
                  complete = True
              else:
                  alter_number_list[left_value], alter_number_list[right_value] = alter_number_list[right_value], alter_number_list[left_value]
          alter_number_list[number_list_min], alter_number_list[right_value] = alter_number_list[right_value] = alter_number_list[number_list_min]
          return alter_number_list
      else: 
          pivot_value = alter_number_list[number_list_min]
          left_value = number_list_min + 1
          right_value = number_list_max
          complete = False
          while not complete:
              while left_value &lt;= right_value and alter_number_list[left_value] &gt;= pivot_value:
                  left_value = left_value + 1
              while alter_number_list[right_value] &lt;= pivot_value and right_value &gt;= left_value:
                  right_value = right_value - 1
              if right_value &lt; left_value:
                  complete = True
              else:
                  alter_number_list[left_value], alter_number_list[right_value] = alter_number_list[right_value], alter_number_list[left_value]
          alter_number_list[number_list_min], alter_number_list[right_value] = alter_number_list[right_value] = alter_number_list[number_list_min]
          return alter_number_list   
  
  import random
  print(&quot;This program will sort a list of random numbers using a user determined sorting algorithm.&quot;)
  sorting_algorithms = [&quot;Selection Sort&quot;, &quot;Bubble Sort&quot;, &quot;Insertion Sort&quot;, &quot;Quick Sort&quot;]
  sorting_orders = [&quot;Ascending&quot;, &quot;Descending&quot;]
  number_list = []
  while True:
      try:
          random_numbers = int(input(&quot;Input number of random integers generated: &quot;))
          print(&quot;Sorting Algorithms: &quot;)
          for sort in range (0, len(sorting_algorithms)):
              print(f&quot;{sort+1} - {sorting_algorithms[sort]}&quot;) 
          sorting_algorithm = int(input(&quot;Select sorting algorithm: &quot;))
          print(&quot;Sorting Orders: &quot;)
          for sort in range (0, len(sorting_orders)):
              print(f&quot;{sort+1} - {sorting_orders[sort]}&quot;) 
          sorting_order = int(input(&quot;Select sorting algorithm order: &quot;))
  
          if random_numbers &lt; 1 or random_numbers &gt; 999999:
              print(&quot;Invalid input, integer values greater then or equal to one and integer values less then or equal to 999999 are accepted.&quot;)
              continue
          elif sorting_algorithm &lt; 1 or sorting_algorithm &gt; 4:
              print(&quot;Invalid input, integer values greater then or equal to one and integer values less then or equal to four are accepted.&quot;)
              continue
          elif sorting_order &lt; 1 or sorting_order &gt; 2:
              print(&quot;Invalid input, integer values greater then or equal to one and integer values less then or equal to two are accepted.&quot;)
              continue
  
          for i in range(random_numbers):
              number_list.append(random.randint(0, 999999))
          print (number_list)
          
          number_list_min = 0
          number_list_max = len(number_list) - 1
  
          if sorting_algorithm == 1:
              altered_number_list = selection_sort(number_list, sorting_order)
              break
          elif sorting_algorithm == 2:
              altered_number_list = bubble_sort(number_list, sorting_order)
              break
          elif sorting_algorithm == 3:
              altered_number_list = insertion_sort(number_list, sorting_order)
              break
          elif sorting_algorithm == 4:
              altered_number_list = quick_sort(number_list, number_list_min, number_list_max, sorting_order)
              break 
      except:
          print(&quot;Invalid input, integer values in the program specified parameters are accepted.&quot;)
  print(altered_number_list)
  </code></pre>
  <p>In the code above, I am able to access options 1, 2, and 3 with no difficulty but I am unable to access the 4th option as it displays an error message. At this point, I have tried renaming variables, using different loops and operations, and creating separate functions but I am still unable to access the 4th option which is the quick sort algorithm. Any help is greatly appreciated!</p>
  <p>Here is the code for the quick sort and partition sort:</p>
  <pre><code>def quick_sort(altered_number_list, number_list_min, number_list_max, sorting_order):
      if number_list_min &lt; number_list_max:
          split_value = partition_sort(altered_number_list, number_list_min, number_list_max, sorting_order)
          quick_sort(altered_number_list, number_list_min, split_value-1, sorting_order)
          quick_sort(altered_number_list, split_value+1, number_list_max, sorting_order)
  
  def partition_sort(alter_number_list, number_list_min, number_list_max, sorting_order):
      if sorting_order == 1:
          pivot_value = alter_number_list[number_list_min]
          left_value = number_list_min + 1
          right_value = number_list_max
          complete = False
          while not complete:
              while left_value &lt;= right_value and alter_number_list[left_value] &lt;= pivot_value:
                  left_value = left_value + 1
              while alter_number_list[right_value] &gt;= pivot_value and right_value &gt;= left_value:
                  right_value = right_value - 1
              if right_value &lt; left_value:
                  complete = True
              else:
                  alter_number_list[left_value], alter_number_list[right_value] = alter_number_list[right_value], alter_number_list[left_value]
          alter_number_list[number_list_min], alter_number_list[right_value] = alter_number_list[right_value] = alter_number_list[number_list_min]
          return alter_number_list
      else: 
          pivot_value = alter_number_list[number_list_min]
          left_value = number_list_min + 1
          right_value = number_list_max
          complete = False
          while not complete:
              while left_value &lt;= right_value and alter_number_list[left_value] &gt;= pivot_value:
                  left_value = left_value + 1
              while alter_number_list[right_value] &lt;= pivot_value and right_value &gt;= left_value:
                  right_value = right_value - 1
              if right_value &lt; left_value:
                  complete = True
              else:
                  alter_number_list[left_value], alter_number_list[right_value] = alter_number_list[right_value], alter_number_list[left_value]
          alter_number_list[number_list_min], alter_number_list[right_value] = alter_number_list[right_value] = alter_number_list[number_list_min]
          return alter_number_list   
  </code></pre>
  <p>I believe the main issue lies in the following code:</p>
  <pre><code>while True:
      try:
          random_numbers = int(input(&quot;Input number of random integers generated: &quot;))
          print(&quot;Sorting Algorithms: &quot;)
          for sort in range (0, len(sorting_algorithms)):
              print(f&quot;{sort+1} - {sorting_algorithms[sort]}&quot;) 
          sorting_algorithm = int(input(&quot;Select sorting algorithm: &quot;))
          print(&quot;Sorting Orders: &quot;)
          for sort in range (0, len(sorting_orders)):
              print(f&quot;{sort+1} - {sorting_orders[sort]}&quot;) 
          sorting_order = int(input(&quot;Select sorting algorithm order: &quot;))
  
          if random_numbers &lt; 1 or random_numbers &gt; 999999:
              print(&quot;Invalid input, integer values greater then or equal to one and integer values less then or equal to 999999 are accepted.&quot;)
              continue
          elif sorting_algorithm &lt; 1 or sorting_algorithm &gt; 4:
              print(&quot;Invalid input, integer values greater then or equal to one and integer values less then or equal to four are accepted.&quot;)
              continue
          elif sorting_order &lt; 1 or sorting_order &gt; 2:
              print(&quot;Invalid input, integer values greater then or equal to one and integer values less then or equal to two are accepted.&quot;)
              continue
  
          for i in range(random_numbers):
              number_list.append(random.randint(0, 999999))
          print (number_list)
          
          number_list_min = 0
          number_list_max = len(number_list) - 1
  
          if sorting_algorithm == 1:
              altered_number_list = selection_sort(number_list, sorting_order)
              break
          elif sorting_algorithm == 2:
              altered_number_list = bubble_sort(number_list, sorting_order)
              break
          elif sorting_algorithm == 3:
              altered_number_list = insertion_sort(number_list, sorting_order)
              break
          elif sorting_algorithm == 4:
              altered_number_list = quick_sort(number_list, number_list_min, number_list_max, sorting_order)
              break 
      except:
          print(&quot;Invalid input, integer values in the program specified parameters are accepted.&quot;)
  </code></pre>