python ValueError中计算器类型程序出错

时间:2016-08-30 19:16:50

标签: python

这是我的剧本,我是python的新手,但是我已经开始接受这个了,请在答案中原谅我这样做,并记住我是新手。

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

但是我得到了这个:

Traceback (most recent call last):
  File "E:/Python/calculator.py", line 26, in <module>
    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 <module>
    elif reply--'yes':
TypeError: bad operand type for unary -: 'str'

在'你想要别的什么'之后我输入'是'。

2 个答案:

答案 0 :(得分:3)

elif reply--'yes':应为elif reply == 'yes':

答案 1 :(得分:1)

你有一个错字

elif reply--'yes'

当然应该是

elif reply=='yes'