How to weed out inputs that aren't in a list
本问题已经有最佳答案,请猛点这里访问。
我有一个代码,让某人输入周期表前五个元素中的一个,我需要一种方法来说明输入是否不在列表中。到目前为止,我已经知道了,但它每次都说它是错误的(工作是输入变量):
1 2 | if (work is not 'H','He','Li','Be',"B"): print ("That is not in the list of elements. Try again.") |
假设输入变量
1 2 | if work not in ('H', 'He', 'Li', 'Be', 'B'): print('That is not in the list of elements. Try again.') |