輸入I:體重,身高,年齡,性別
處理P:
輸出O:BMR
""""
auther:
function:Calculating BMR
version:v1.0
data:2019/3/17
"""
def main():
gender = 'woman'
#kg
weight = 61
#cm
height = 153
age = 26
if gender == 'man':
bmr = (13.7 * weight) + (5.0 * height) - (6.8 * age) + 66
elif gender == 'woman':
bmr = (9.6 * weight) + (1.8 * height) - (4.7 * age) + 665
else:
bmr = -1
if bmr != -1:
print 'BMR:',bmr
else:
print 'The gender is not supported for the time being!'
if __name__== '__main__':
main()
數值類型:
int('4')
>>>4
eval('4')
>>>4
基礎代謝率5.0
"""" auther: function: 1.Calculating BMR 2.Allow user input 3.Allow user input by once version:v3.0 data:2019/3/17 """ def bmr(input_str): try: str_list = input_str.split(' ') str_list = input_str.split(' ') gender = str_list[0] weight = float(str_list[1]) height = float(str_list[2]) age = int(str_list[3]) if gender == 'man': bmr = (13.7 * weight) + (5.0 * height) - (6.8 * age) + 66 elif gender == 'woman': bmr = (9.6 * weight) + (1.8 * height) - (4.7 * age) + 665 else: bmr = -1 if bmr != -1: print 'Your gender: {} ,Your weight: {} ,Your height: {} ,Your age: {} '.format(gender, weight, height, age) print 'Your BMR is : {} cal'.format(bmr) else: print 'The gender is not supported for the time being!' print y_or_n = raw_input('Quit (y or n )?:') print 'Are you sure to exit? ' except ValueError: print 'Please enter the right infoemation!' except IndexError: print 'Input information too less!' except: print 'Error!' def main(): y_or_n = raw_input('Quit (y or n )?:') while y_or_n != 'y': print('Please enter the following information(separate with Spaces):') input_str=raw_input('Gender Weight(kg) Height(cm) Age: ') bmr(input_str) y_or_n = raw_input('Quit (y or n )?:') print 'Bye!!!' if __name__== '__main__': main()