Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 变量验证以输出消息_Python - Fatal编程技术网

Python 变量验证以输出消息

Python 变量验证以输出消息,python,Python,我有3个变量,总共应该是120。我已经核实过了。变量应等于0或20或40或60或80或100或120。我也做了验证,但现在我需要的是让我的程序检查变量1是100,变量2是0还是20,变量3是0还是20,以输出消息。然后我需要检查变量1是否为40或60或80变量2是否为0或20或40或60或80变量3是否为0或20或40或60以输出不同的消息 if pass_credit + defer_credit + fail_credit != 120: print("Total incorrect

我有3个变量,总共应该是120。我已经核实过了。变量应等于0或20或40或60或80或100或120。我也做了验证,但现在我需要的是让我的程序检查变量1是100,变量2是0还是20,变量3是0还是20,以输出消息。然后我需要检查变量1是否为40或60或80变量2是否为0或20或40或60或80变量3是否为0或20或40或60以输出不同的消息

if pass_credit + defer_credit + fail_credit != 120:
    print("Total incorrect!")
elif pass_credit == 120 and defer_credit == 0 fail_credit == 0:
    print("Progress")
    break
elif pass_credit == 100 and defer_credit == 0 or 20 and fail_credit == 0 or 20:
    print("Progress - module trailer")
    break
这就是我目前所知道的


提前感谢

如果您想对所有好的组合(带值)使用一般信息,请使用:

输出:

The values are: Variable 1 is: 80, Variable 2 is: 40, Variable 3 is: 0

如果您希望每个可能的组合都有不同的消息,请继续您的
elif
s以涵盖所有选项(使用@gelonida对syntex的更正)。没有聪明的方法可以做到这一点。

这一行的语义是错误的:

elif pass_credit == 100 and defer_credit == 0 or 20 and fail_credit == 0 or 20:
要么写

elif pass_credit == 100 and (defer_credit == 0 or defer_credit == 20) and (fail_credit == 0 or fail_credit == 20):
或写

elif pass_credit == 100 and defer_credit in (0, 20) and fail_credit in (0, 20):

到目前为止,您尝试了什么?您到底在问什么?使用按钮。
break
用于退出
循环。因为您没有
循环
,所以不要使用它。我有一个循环,如果满足任何条件,我需要它退出循环。这只是我代码的一部分谢谢。这回答了我的问题!
elif pass_credit == 100 and defer_credit in (0, 20) and fail_credit in (0, 20):