How do I limit my users input to a single digit? (Python)
<p>I want my program to say 'invalid input' if 2 digits or more are entered so is there a way i can limit my users input to a single digit in python?</p>

<p>This is my code:</p>

<pre><code>print('List Maker')
tryagain = ""

while 'no' not in tryagain:
    list = []

    for x in range(0,10):
        number = int(input("Enter a number: "))
        list.append(number)

    print('The sum of the list is ',sum(list))
    print('The product of the list is ',sum(list) / float(len(list)))
    print('The minimum value of the list is ',min(list))
    print('The maximum vlaue of the list is ',max(list))
    print(' ')
    tryagain = input('Would you like to restart? ').lower()
    if 'no' in tryagain:
        break
print('Goodbye')
</code></pre>

<p>Use a <code>while</code> loop instead of a <code>for</code> loop, break out when you have 10 digits, and refuse to accept any number over 9:</p>

<pre><code>numbers = []
while len(numbers) &lt; 10:
    number = int(input("Enter a number: "))
    if not 1 &lt;= number &lt;= 9:
        print('Only numbers between 1 and 9 are accepted, try again')
    else:
        numbers.append(number)
</code></pre>

<p>Note that I renamed the list used to <code>numbers</code>; <code>list</code> is a built-in type and you generally want to avoid using built-in names.</p>

python