新手问题!如何针对 5 种不同条件验证一个变量

问题描述 投票:0回答:1

我是 python 的新手,我正在尝试为复制更改机器的课程制作小程序。该程序要求用户输入一个金额,它必须是 5、10、20、50 或 100。即输入必须是那个或应该拒绝它。到目前为止,我已经尝试了很多不同的 or 组合,但我无法让它工作。

   if (deposit_amount == 5) or (deposit_amount == 10) or (deposit_amount == 20) or (deposit_amount == 50) or (deposit_amount == 100)::
        else print ("The deposit note value must be in$'s (5, 10, 20, 50 or 100)\n"```

I'm going mad 

Thanks 


I've tried combs of the above (I know it needs an or operator) but I can't understand how
python selection
1个回答
0
投票

您可以将

if
语句与
in
运算符结合使用:

if deposit_amount in [5, 10, 20, 50, 100]:
© www.soinside.com 2019 - 2024. All rights reserved.