Reject or loop over user input if two conditions not met
<p>I am a real beginner with Python, although I am loving every minute of it so far.</p>

<p>I am making a little program that takes user input and then does stuff with it. My issue is that the numbers the user inputs have to </p>

<p>(1) All add up to not more than one (i.e. a1+ a2+ a3 \leq 1)</p>

<p>(2) Each individually be &lt; 1.</p>

<p>Here is my code thus far (just the essential middle bit):</p>

<pre><code> num_array = list()


  a1  = raw_input('Enter percentage a (in decimal form): ')
  a2 = raw_input('Enter percentage b (in decimal form): ')
  ...
  an = raw_input('Enter percentage n (in decimal form): ')


li = [a1, a2, ... , an]

for s in li:
   num_array.append(float(s))
</code></pre>

<p>And I would love to build in something to make it demand the user re-inputs things if their inputs either exceed the requirement that </p>

<p>a1+a2+a3 >1</p>

<p>or that a1>1, a2>1, a3>1 etc.</p>

<p>I have a feeling this would be really easy to implement, but with my limited knowledge I am stuck!</p>

<p>Any help would be much appreciated :-)</p>

<pre><code>input_list = []
input_number = 1
while True:

    input_list.append(raw_input('Enter percentage {} (in decimal form):'.format(input_number))

    if float(input_list[-1]) &gt; 1:     # Last input is larger than one, remove last input and print reason
        input_list.remove(input_list[-1])
        print('The input is larger than one.')
        continue

    total = sum([float(s) for s in input_list])
    if total &gt; 1:    # Total larger than one, remove last input and print reason
        input_list.remove(input_list[-1])
        print('The sum of the percentages is larger than one.')
        continue

    if total == 1:    # if the sum equals one: exit the loop
        break

    input_number += 1
</code></pre>

python loops input