我想用python做一个计算器,检查用户的答案是否匹配,有这样一个问题,python给我一个错误:
else:
^
SyntaxError: invalid syntax
带代码:
while True:
def code():
print(Back.RED)
what = input("Что делаем? (+, -, *, /, %, ^): ")
if what != ("+" and "-" and "*" and "/" and "%" and "^"):
print("Не понял тебя")
code()
else:
print(Back.MAGENTA)
a = float(input("Введите первое число: "))
print(Back.CYAN)
b = float(input("Введите второе число: "))
if what == "+":
c = a + b
if what == "-":
c = a - b
if what == "*":
c = a * b
if what == "/":
c = a / b
if what == "%":
c = a % b
if what == "^":
c = a ** b
print(Back.GREEN)
print(Style.BRIGHT)
print("Результат: " + str(c))
input()
请解释一下哪里出了问题,不要骂太多,这是我继hello world之后的第二个程序
提前感谢您的回复!