2017-02-28 310 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

相關問題