我是python新手,不到一周前就开始编写代码了。我决定尝试建立一个单独的diget计算器。我知道我的代码可能写得不是很好,建议很感激,但请不要只是讨厌它。好了,现在来看看代码。我得到的错误代码说,它不能分配一个Operator。我知道这意味着它不能把变量变成from string to int,但我不知道如何修复它。我在第25、28、31、34行得到了错误。谢谢!在calculate = input("Enter the problem in the format x + y = z ")
opperations = ["+", "-", "*", "/"]
numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
space = " "
def opperation():
if opperations == "+":
A = 1
elif opperations == "-":
A = 2
elif opperations == "*":
A = 3
elif opperations == "/":
A = 4
if calculate[0] in numbers:
if len(calculate) > 1:
if calculate[1] == space:
calculate[0] = a
a = int(a)
calculate[4] = b
b = int(b)
if A == 1:
a + b = c
print (c)
elif A == 2:
a - b = c
print (c)
elif A == 3:
a * b = c
print(c)
elif A == 4:
a / b = c
print(c)
else:
print("Sorry invalid text")
else:
print("Sorry invalid text")
else:
print("Sorry invalid text")
else:
print("Sorry invalid text")