"""" auther: function: 1.Calculating BMR 2.Allow user input 3.Allow user input by once version:v3.0 data:2019/3/17 """ 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: ') 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 )?:') except ValueError: print 'Please enter the right infoemation!' except IndexError: print 'Input information too less!' except: print 'Error!' if __name__== '__main__': main()
python小象學院: BMR------ 基礎代謝率4.0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.