Luogu Question Writing Python Language | P5714 Obesity Problem

Learn Python from a young age! Record the questions in the Luogu Python learning and exam preparation process, and record every moment.

Attached is a summary post: Luogu’s Python language | Summary_Blog of a communicator who loves programming-CSDN Blog


[Title description]

BMI index is a commonly used international standard to measure the degree of fatness and thinness of a human body. Its algorithm is m/ h^ 2, where  m  refers to weight (kilograms) and ℎ h  refers to height (meters). The different body shape ranges and judgment results are as follows:

  • Less than 18.5: Underweight, output Underweight;
  • Greater than or equal to 18.5 and less than 24: normal weight, output Normal;
  • Greater than or equal to 24: Obesity, not only output the BMI value (using the default precision of cout), then wrap the line, but also output Overweight;

Now given the weight and height data, it is necessary to determine the body shape status based on the BMI index and output the corresponding judgment.

For non-C++ languages, when outputting, please round to keep six significant digits for output. If there is a suffix of 00 in the decimal part, do not output the suffix of 00.

Note that to six significant figures is not to six decimal places. For example, 123.4567 should be output as 123.457, and 5432.10 should be output as 5432.1.

【enter】

A total of one line.

The first line contains a total of 2 floating point numbers, m and h , representing weight (unit: kg) and height (unit: m) respectively.

【Output】

Output one string per line, indicating the corresponding judgment based on BMI. In particular, please refer to the title for special handling of the Overweight situation.

【Input sample】

70 1.72

【Output sample】

Normal

[Detailed code explanation]

m,h = [eval(i) for i in input().split()] 
bmi = m / h**2  
if bmi < 18.5: 
    print("Underweight")
elif bmi < 24: 
    print("Normal")
else:
    if int(bmi) == bmi:  
        print(int(bmi)) 
    else:
        print("%.6g" % bmi) 
    print("Overweight")

【operation result】

70 1.72
Normal

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132777772