#! /usr/bin/env python3 # def bmi_english ( weight_lb, height_in ): #*****************************************************************************80 # ## bmi_english() computes the BMI (body mass index). # # Discussion: the BMI has a simple formula when the input is defined in metric units # This program accepts data in English units (pounds and inches) and applies the # correct unit conversions. An "ideal" BMI is between 18.5 and 30. Above 30 begins # to count as "obese" and below 18.5 is considered "underweight". # # Example: bmi_english ( 150, 60 ) returns the value 29.30 # # Modified: 12 May 2022 # # Author: John Burkardt # # Reference: https://en.wikipedia.org/wiki/Body_mass_index # # Input: # weight_lb, the weight in pounds. # height_in, the height in inches. # # Output: # value, the body mass index. # value = ( weight_lb / 2.204 ) * ( 39.370 / height_in )**2 return value def bmi_english_test ( ): #*****************************************************************************80 # ## bmi_english_test() tests bmi_english(). # print ( '' ) print ( 'value = bmi_english ( weight_lb, height_in ) demonstration:' ) print ( '' ) value = bmi_english ( 100, 50 ) print ( ' bmi_english(100,50) = ', value ) value = bmi_english ( 150, 60 ) print ( ' bmi_english(150,60) = ', value ) value = bmi_english ( 200, 70 ) print ( ' bmi_english(200,70) = ', value ) def c_to_f ( c ): #*****************************************************************************80 # ## c_to_f() converts Celsius to Fahrenheit temperature. # f = ( 9 / 5 ) * c + 32 return f def c_to_k ( c ): #*****************************************************************************80 # ## c_to_k() converts Celsius temperature to Kelvin. # k = c + 273.15 return k def cosm_sinn ( m, n ): #*****************************************************************************80 # ## cosm_sinn() evaluates integral(0 <= theta <= pi/2) cos^m(theta) sin^n(theta) dtheta # from math import pi from my_library import double_factorial # backslash lets us split the following long line value = double_factorial ( m - 1 ) * double_factorial ( n - 1 ) \ / double_factorial ( m + n ) if ( ( m % 2 == 0 ) and ( n % 2 == 0 ) ): value = value * pi / 2.0 return value def cosm_sinn_test ( ): #*****************************************************************************80 # ## cosm_sinn_test() tests cosm_sinn(). # print ( '' ) print ( 'cosm_sinn_test():' ) print ( ' Test cosm_sinn()' ) print ( '' ) print ( 'm n integral value' ) for m in range ( 2, 5 ): print ( '' ) for n in range ( 2, 5 ): print ( m, n, cosm_sinn ( m, n ) ) return def double_factorial ( n ): #*****************************************************************************80 # ## double_factorial() evaluates the double factorial function. # # Discussion: # # The double factorial function of n is represented by n!! # # If n is even, n!! = 2 * 4 * ... * n-2 * n # # If n is odd, n!! = 1 * 3 * ... * n-2 * n # # Modified: # # 17 January 2023 # # Author: # # John Burkardt # # Input: # # integer n: the argument. # # Output: # # integer value: the value of n!! # value = 1 while ( 0 < n ): value = value * n n = n - 2 return value def double_factorial_test ( ): #*****************************************************************************80 # ## double_factorial() evaluates the double factorial function. # exact = [ 1, 1, 2, 3, 8, 15, 48, 105, 384, 945, 3840, 10395, 46080, 125135, 645120 ] exact_num = len ( exact ) print ( '' ) print ( 'double_factorial_test():' ) print ( ' Test double_factorial(n)' ) print ( '' ) for n in range ( 0, exact_num ): value = double_factorial ( n ) print ( n, value, exact[n] ) return def f_to_c ( f ): #*****************************************************************************80 # ## f_to_c() converts Fahrenheit temperatures to Celsius. # c = ( 5 / 9 ) * ( f - 32 ) return c def f_to_k ( f ): #*****************************************************************************80 # ## f_to_k() converts Fahrenheit temperatures to Kelvin. # c = f_to_c ( f ) k = c + 273.15 return k def k_to_c ( k ): #*****************************************************************************80 # ## k_to_c() converts Kelvin temperatures to Celsius. # c = k - 273.15 return c def k_to_f ( k ): #*****************************************************************************80 # ## k_to_f() converts Kelvin temperatures to Fahrenheit. # c = k_to_c ( k ) f = c_to_f ( c ) return f if ( __name__ == "__main__" ): bmi_english_test ( ) double_factorial_test ( ) cosm_sinn_test ( )