title: How to I create a function that continuously adds elements to a list until they are equal to a certain variable?
body: <p>I am in my first computer science course and am struggling to create these functions for my project. To summarize, I am supposed to build a simulation that takes an uncut 'steak' which is represented by a list [0,100], and build 3 functions called fast_slices, slow_slices, and average_chop_time.</p>
  <p>Project 2:</p>
  <p>Let’s agree to store all of the slices we make as an ordered list of numbers, where
  [0,100] represents an uncut steak.</p>
  <p>First, write two functions called fast slices and slow slices. Each function should take two inputs,
  slice list and size limit. The slice list input represents the current list of slices (see previous
  paragraph), and size limit represents the size we’re trying to get all pieces to be smaller than or equal
  to. The fast slices function should take the slice list and continually add random slices until all
  pieces are within the size limit. The slow slices function should take the slice list and continually
  look for pieces larger than the size limit and (from left to right) slicing them into smaller pieces with size exactly equal to the size limit. Both fast slices and slow slices must return the new slice list.</p>
  <p>Second, write another function called ave chop time which takes six inputs: slice list, fast limit,
  slow limit, fast cost, slow cost, and n. The slice list once again represents a list of slices (probably
  just an uncut steak [0,100]), the fast limit is the size limit for the fast slices, slow limit is the size limit for the slow slices, fast cost is the time it costs to do a fast slice, and slow cost is the time it costs to do a slow slice. The function should take the slice list, run it through the fast slices function using fast limit as the size limit, then run it through the slow slices function using slow limit as the size limit. After each function, you can calculate the number of slices performed by comparing the length of the slice list before and after the function. Once you know the number of fast slices and slow slices, multiply them by fast cost and slow cost, respectively, and add together to calculate the total time it took to chop the beef. Finally, this whole process should be repeated n times and the average total time should be returned.</p>
  <p>SAMPLE WHEN THE SCRIPT IS RUN:</p>
  <pre><code>Welcome to my average chop time calculator!
  Give the overall size limit: 5
  Give the time cost for a random slice: 0.6
  Give the time cost for an accurate slice: 2.1
  The average chopping times by random slice size limit:
  </code></pre>
  <p>OUTPUT:</p>
  <pre><code>fast_limit: 5.000, 10.000, 15.000, 20.000
  ave_chop_time: 63.834000, 36.726000,  35.550000, 35.802000
  </code></pre>
  <p>WHAT I HAVE SO FAR:</p>
  <pre><code>import random
  
  slice_list = [0, 100]
  size_limit = L
  
  def fast_slices(size_limit, slice_list):  #is this correct?
      i = 0
      fast_slice_diff = [slice_list[i+1]-slice_list[i] for i in range(len(slice_list-1))]
      if min(fast_slice_diff) &lt;= size_limit:
          return fast_slices
      else:
          slice_list.append(random.uniform(0,100)
          list.sort(slice_list)
  
  def slow_slices(size_limit, slice_list):
     i = 0
     slow_slice_diff = [slice_list[i+1]-slice_list[i] for i in range(len(slice_list-1))]
     if min(slow_slice_diff) == size_limit:
         return slow_slices
     elif min(slow_slice_diff) &gt; size_limit:
             slice_list.append(random.uniform(0,100)
  </code></pre>