python ValueError中计算器类型程序出错
这是我的脚本,我是python新手,但我是来理解这一点的,请原谅我的回答,并记住我是新手python ValueError中计算器类型程序出错,python,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, numb
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'
回溯(最近一次呼叫最后一次):
文件“E:/Python/calculator.py”,第26行,在
number=int(输入())
ValueError:基数为10的int()的文本无效:“”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“E:/Python/calculator.py”,第37行,在
以利夫回答“是”:
TypeError:一元操作数的操作数类型错误-:“str”
在“你还想要什么”之后,我输入“是”。elif-reply--“是”:
应该是elif-reply=='yes':
elif-reply--'yes':
应该是elif-reply=='yes':
你有打字错误
elif reply--'yes'
当然应该是这样
elif reply=='yes'
你打错了
elif reply--'yes'
当然应该是这样
elif reply=='yes'
问题很清楚:
reply=='yes'
问题很清楚:reply=='yes'