如何使用“或”在条件“ if”中添加多个字符串?

时间:2019-04-05 22:44:35

标签: python-3.x input

我有一个使用weight_type.upper()的解决方案,但我仍在学习,我想知道为什么[weight_type =='L'或'l':]没有给我正确的答案。

weight = input("What is your weight? ")
weight_type = input("Is it in (L)bs or (K)g? ")
if weight_type == 'L' or 'l':
    print(f"Output weight in (K)g is {int(float(weight))*0.453592}")
elif weight_type == "K" or 'k':
    print(f"Output weight in (L)bs is {int(float(weight))*2.20462}")
else:
    print("Unsupported weight type")

结果:

What is your weight? 70
Is it in (L)bs or (K)g? k
Output weight in (K)g is 31.75144

Process finished with exit code 0

0 个答案:

没有答案