2017-02-28 279 views
-2
def male_resting_metabolic_rate(weight,height,age): 

    '''Takes in the weight, height, and age of a male individual 
    and returns the resting metabolic rate 

Example answers: 
    male_resting_metabolic_rate(80,180,48) = 1751''' 

    male_resting_metabolic_rate = int((88.4+13.4*weight)+(4.8*height)-(5.68* age)) 

if __name__ == "__main__": 
print("This program will calculate the resting metabolic rate of an individual") 

    #Gather the inputs for the functions 

weight = input("What is your weight in kilograms?") 
height = input("What is your height in centimeters?") 
age = int(input("What is your age?" + "(between 1-110):")) 

print("Your resting metabolic rate is",male_resting_metabolic_rate(input,input,input)) 

为什么它说我在第10行和第24行有错误?超新的这个,所以我很抱歉,如果答案相当明显。TypeError:*:'float'和'builtin_function_or_method'的不受支持的操作数类型

+2

'输入,输入,input':3倍'input'方法,而不是你在上面定义的变量!你也错过了2个变量的整数转换。 –

+0

这里有很多问题。首先是'input'返回一个字符串,所以你需要将权重转换为数值,然后再乘以它。 'male_resting_metabolic_rate(input,input,input))'没有意义,你想做什么? – roganjosh

+0

@ Jean-FrançoisFabre如何将变量转换为整数?我再次道歉,我觉得这是非常基本的! –

回答

-1

发现至少两处错误:您需要在python中用“return”返回值。你也需要通过名称不是“输入”

传递参数试试这个:

def male_resting_metabolic_rate(weight,height,age): 

    '''Takes in the weight, height, and age of a male individual 
    and returns the resting metabolic rate 

    Example answers: 
    male_resting_metabolic_rate(80,180,48) = 1751''' 

    return int((88.4+13.4*weight)+(4.8*height)-(5.68* age)) 

if __name__ == "__main__": 
    print("This program will calculate the resting metabolic rate of an individual") 

    #Gather the inputs for the functions 

    weight = float(input("What is your weight in kilograms?")) 
    height = float(input("What is your height in centimeters?")) 
    age = int(input("What is your age?" + "(between 1-110):")) 

    print("Your resting metabolic rate is",male_resting_metabolic_rate(weight, height, age)) 
+0

我刚刚为此完成了一个解决方案。请不要在问题中发布所有混乱格式的答案,您需要在编辑器中修复它。 – roganjosh

+0

@roganjosh我对此表示歉意 - 我不知道如何在相同的回复中格式化代码和评论。我想通了,但非常感谢! –

+0

@ J.您在评论中使用反引号进行格式化。对于代码块,您可以复制/粘贴,突出显示整个事物并使用'ctrl' +'k'。但是,这个答案也需要改进格式。没有理由格式不正确的问题和答案。 – roganjosh

相关问题