python小象学院: BMR------ 基础代谢率4.0

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


猜你喜欢

转载自blog.csdn.net/qq_26572229/article/details/88634887
今日推荐