def Functional_Output(Validate_Input):
try:
while '(' in Validate_Input and ')' in Validate_Input:
Validate_Output = Validate_Input.count('(')
Intake_Input = Validate_Input.find('(')
fin = Validate_Input.find(')')+1
while Validate_Output > 1:
Intake_Input = Validate_Input.find('(', Intake_Input+1)
Validate_Output -= 1
receive_value = Validate_Input[Intake_Input:fin]
receive_input = calcula(receive_value.replace('(', ''). replace(')', ''))
Validate_Input = Validate_Input.replace(recieve_value, recieve_input)
DisplayAnswer = float(AddFunction(Validate_Input))
except:
DisplayAnswer = "Error"
return DisplayAnswer
def AddFunction(Validate_Input):
add_selection = Validate_Input.split()
while len(add_selection) != 1:
for index in range(len(add_selection)):
if add_selection[index] == '/':
add_selection[index] = str(float(add_selection[index-1])/float(add_selection[index+1]))
add_selection.pop(index+1)
add_selection.pop(index-1)
break
elif add_selection[index] == '*':
add_selection[index] = str(float(add_selection[index-1]) * float(add_selection[index+1]))
add_selection.pop(index+1)
add_selection.pop(index-1)
break
if not '/' in add_selection and not '*' in add_selection:
while len(add_selection) !=1:
for index in range(len(add_selection)):
add_selection[index] = str(float(add_selection[index]) + float(add_selection[index+1]))
add_selection.pop(index+1)
break
return add_selection[0]
root = tkinter.Tk()
root.resizable(0, 0)
root.title("Calculator")
txtDisplay =tkinter.StringVar()
operator = ""
App_Function = Calculator_App(root)
root.mainloop()
当我点击按钮'9',然后'+',然后'1'时,该条目返回'错误'而不是'10'的消息!为什么是这样? 它可能是与addFunction函数和索引有关吗?为什么我的计算器不能计算答案?
请不要进行代码转储,尝试隔离代码似乎在做的事情,而不是预期的部分。 –
为什么这肯定意味着你可以运行该程序并亲自查看?我只是想帮忙! –
这几乎肯定不是你的错误的原因,但只是一个建议:最常见的Python风格是对模块,函数和变量使用'lower_case_names_with_underscores',并使用CapitolizedNamesWithoutUnderscores作为类。遵循这个约定会让其他人更容易阅读你的代码。并非所有的标准库模块都遵循本指南(有文档记载,以及[PEP 8](https://www.python.org/dev/peps/pep-0008/)中的许多其他样式建议,但建议对于新代码 – Blckknght