我的macro_percentages
返回3個整數的列表。我已經測試過了,輸出是正確的。但是,當我打印想出我得到的每個打印語句中的0.0s
。也有一些是造成我的值變爲0打印整數和浮點數,但得到0的
macro_percentages --> [20,20,60]
代碼:
macro_percentages = ask_macro_percentages()
print "Your meal plan consists of: " + str(float((macro_percentages[0]/100) * calorie_deficit)) + "g of protein, ",
print str(float((macro_percentages[1]/100) * calorie_deficit)) + "g of fat, ",
print "and " + str(float((macro_percentages[2]/100) * calorie_deficit)) + "g of carbohydrates"
我認爲你是在Python2。 X。您應該嘗試將您的值浮動,或除以100.0 – sberry
我建議在開始計算之前簡單地添加此行:'macro_percentages = [float(value)for macro_percentages]' –