gpt4 book ai didi

python - 为什么 if not 操作 == '/' 或 '*' 或 '+' 或 '-' : give me a syntax error,

转载 作者:行者123 更新时间:2023-12-02 02:24:37 25 4
gpt4 key购买 nike

if not operation == '/' or '*' or '+' or '-':
print('not a valid answer, try again')
operation = (input('Please enter what operation you would like to do, / is divide, * is multiply, + is plus and - is minus')

最佳答案

operation = (input('Please enter what operation you would like to do, / is divide, * is multiply, + is plus and - is minus')

您忘记添加第二个右大括号。在这种情况下,只需删除左大括号即可。

此外,您的 if 语句将始终为 True。以下代码将起作用:

if not operation in ['/', '*', '+', '-']: # test if operation is one of /, *, + and -
print('not a valid answer, try again')
operation = input('Please enter what operation you would like to do, / is divide, * is multiply, + is plus and - is minus')

关于python - 为什么 if not 操作 == '/' 或 '*' 或 '+' 或 '-' : give me a syntax error,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65878015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com