TypeError:不支持*的操作数类型:“float”和“builtin function”或“u method”

2024-09-28 22:19:42 发布

您现在位置:Python中文网/ 问答频道 /正文

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行有错误?这是一个全新的问题,如果答案很明显的话,我很抱歉。在


Tags: andoftheininputageyourrate
1条回答
网友
1楼 · 发布于 2024-09-28 22:19:42

发现了至少两个错误:您需要在python中使用“return”返回值。此外,您还需要按名称传递参数,而不是“input”

试试这个:

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

相关问题 更多 >