"or" Condition Causing Problems With "if"
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
Solution 1:
'a' evaluates to True, so you need to construct your if statement correctly.
def chooseDim( ):
**choice = input ('Do you need to find radius or area? ')
ifchoice== 'A'orchoice== 'a':**
area = 0
area = int(area)
areaSol ( )
elifchoice== 'R'orchoice== 'r':
radSol ( )
else:
print ('Please enter either A/a or R/r.')
chooseDim ( )
Solution 2:
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':
Solution 3:
ifchoice== 'A'orchoice=='a':
Post a Comment for ""or" Condition Causing Problems With "if""