“或”条件导致“if”出现问题

2023-12-04

我遇到了问题or函数中的条件。这if语句不断评估为True无论什么价值choice是。当我删除or, the if工作正常。

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 ()

'a' 的计算结果为 True,因此您需要正确构建 if 语句。

def chooseDim ( ):
**choice = input ('Do you need to find radius or area? ')
if choice == 'A' or choice == 'a':**
    area = 0
    area = int(area)
    areaSol ( )

elif choice == 'R' or choice == 'r':

    radSol ( )

else:
    print ('Please enter either A/a or R/r.')
    chooseDim ( )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“或”条件导致“if”出现问题 的相关文章

随机推荐