"或"引起“if”的问题的条件 [英] "or" condition causing problems with "if"
本文介绍了"或"引起“if”的问题的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在函数中遇到或
条件时遇到问题。 if
语句将评估为 True
,无论值 choice
是。当我删除或
时,如果
正常工作。
I'm having trouble with an or
condition in a function. The if
statement keeps evaluating as True
no matter what value choice
is. When I remove the or
, the if
works correctly.
def chooseDim ():
**choice = input ('Do you need to find radius or area? ')
if choice == 'A' or 'a':**
area = 0
area = int(area)
areaSol ()
elif choice == 'R' or 'r':
radSol ()
else:
print ('Please enter either A/a or R/r.')
chooseDim ()
推荐答案
关于或$的答案c $ c>本身是正确的。你真的在问
a
是否为True,它总是如此。但是还有另一种方法:
The answers about or
itself are correct. You're literally asking if "a"
is True, which it always is. But there's an alternative approach:
if choice in 'Aa':
然后再次,没有任何问题:
Then again, there's nothing wrong with:
if choice.lower() == 'a':
这篇关于"或"引起“if”的问题的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文