if / elif / else语句有什么问题

时间:2017-06-06 01:52:35

标签: python python-3.x

此代码的问题是if / elif / else的语法错误。但我不知道为什么它会向我显示错误。

try:
    if ans_three = '+':
        x = add(ans_one,ans_two)
        print("[+] Your Total Number: " + x)
    elif ans_three = '-':
        x = minus(ans_one, ans_two)
        print("[-] Your Total Number: " + x)
    elif ans_three = '*':
        x = minus(ans_one, ans_two)
        print("[*] Your Total Number: " + x)
    elif ans_three = '/':
        x = minus(ans_one, ans_two)
        print("[/] Your Total Number: " + x)
    else:
        print('>> Wrong operators! [+] [-] [*] [/]')
except ValueError:
    print("Invalid Number!")
    StopIteration

这是错误:

if ans_three = '+':
             ^
SyntaxError: invalid syntax

Process finished with exit code 1

我使用的软件是:

PyCharm Community Edition 2017.1.3

0 个答案:

没有答案