Error with calculator type program in python
<pre><code>numbers=[]
while True:
    print('Input Number '+str(len(numbers)+1)+' (or nothing to close):')
    number=input()
    numbers=numbers+[number]
    if number=='':
        print('What do you want to do?')
        answer=input()
        break
        if answer==mean:
            mean
def mean():
    end_mean=reduce(lambda x, y: x + y, numbers) / len(numbers)
    print(end_mean)
</code></pre>

<p>I am trying to make a calculator type program in python which allows you to enter a list of numbers and then select what you do with them. The script above is only the beginning but when i enter the numbers and type in 'mean' when it asks me what to do, it ends the script and shows nothing. I am new to python so please be forgiving as such in the answers.</p>

<p>Edit 3 - </p>

<p>After using answers below i have fixed the script to end up with this:</p>

<pre><code>import functools
numbers=[]

def means():
    end_mean = functools.reduce(lambda x, y: x + y, numbers) / len(numbers)
    print(end_mean)

def sum():
    end_sum = functools.reduce(lambda x, y: x + y, numbers)
    print(end_sum)

def whatDo():
        print('Input Extra Numbers '+str(len(numbers)+1)+' (or nothing to close):')
        try:
            number= int(input())
            numbers.append(number)
        except:
            print('What do you want to do?')
            answer = input()
            if answer == "mean":
                means()

while True:
    print('Input Number '+str(len(numbers)+1)+' (or nothing to close):')
    try:
        number= int(input())
        numbers.append(number)
    except:
        print('What do you want to do?')
        answer = input()
        if answer == "mean":
            means()
            print('Do you want anything else?')
            reply=input()
            if reply=='no':
                break
            elif reply--'yes':
                whatDo()
        else:
            break
</code></pre>

<p>However i get this:</p>

<pre><code>Traceback (most recent call last):
  File "E:/Python/calculator.py", line 26, in &lt;module&gt;
    number= int(input())
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:/Python/calculator.py", line 37, in &lt;module&gt;
    elif reply--'yes':
TypeError: bad operand type for unary -: 'str'
</code></pre>

<p>after the 'Do you want anything else' and i enter 'yes'.</p>

<p>May be this will help you.</p>

<pre><code>numbers=[]

def means():
    end_mean = reduce(lambda x, y: x + y, numbers) / len(numbers)
    print(end_mean)

while True:
    print('Input Number '+str(len(numbers)+1)+' (or nothing to close):')
    try:
        number= int(input())
        numbers.append(number)
    except:
        print('What do you want to do?')
        answer = input()
        if answer == "mean":
            means()
        else:
            break
</code></pre>

<p>What have I changed from your Code? </p>

<ul>
<li>Added a <code>try-except</code> block. This is added so that it can handle the case when you passed <code>''</code> as input.</li>
<li>cast input to <code>int</code> before passing to number, as you need <code>int</code> value to calculate mean, not <code>string</code> values.</li>
<li>You are making a list from the input and then adding to the previous list, which is unnecessary and inefficient. I replace it with <code>numbers.append(number)</code></li>
<li>The unnecessary <code>break</code> statement removed. <code>break</code> is used to get out from the loops. As you use <code>break</code>, you will never see the later statements executed.</li>
</ul>

python