Skip to main content
 首页 » 编程设计

Python 条件语句

2025年05月04日13mq0036

def Fitness(a, b, c):   
    if ((a&b&c) >= 4) & ((a+b+c) >= 13):   
        return('Gold')   
    if ((a&b&c) >= 3) & ((a+b+c) >= 10):   
        return('Silver')    
    if ((a&b&c) >= 2) & ((a+b+c) >= 07):   
        return('Pass')   
    else:   
        return('Fail') 

现在的问题是,当给出 Fitness(2,2,5) 时,控件会跳转到默认值,即。 '失败'。 实际输出在哪里是“通过”。 ?

请您参考如下方法:

注意

a&b&c >= 2 

不同于

a>=2 and b>=2 and c>=2. 

我认为你的意思是第二个,即所有值都大于 2。 (第一个对所有值执行 binary and 并将其与值二进行比较。)