0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

今更なのですが、BMI計算をpythonで、やってみたかったのです。

Last updated at Posted at 2020-10-07

今更なのですが、BMI計算をpythonでやってみたかったのです。
個人の趣味で。全く個人的なメモ程度で。

2つのpythonファイルで

health_check.py
# coding: UTF-8
# 環境がMac OS なので、日本語対応には UTF-8 
#BMI code 
# 名前はhealth_check.py

def bmi(weight, height):
    bmi_data = []
    w = weight
    h = height
    bmi = w/(h*h)
    bmi = round(bmi, 1)
    bmi_data.append(bmi)
    if bmi<18.5:
        ans = "やせ型です"
    elif bmi>=18.5 and bmi<25:
        ans = "標準です"
    else:
        ans = "肥満です"
    bmi_data.append(ans)
    return bmi_data

二つ目がhealth_check_main.py で。

health_check_main.py
# coding: UTF-8
# BMI health_check main
# health_check_main.py
import health_check
weight  = float(input('あなたの体重を入力してください(kg): '))
height0 = float(input('あなたの身長を入力してください(cm): '))
height = height0/100
bj = health_check.bmi(weight, height)
print("----" * 10)
print("あなたのBMI: " + str(bj[0]) + '\nあなたの体型: ' + bj[1])

実行は、Mac OS ターミナルのbashコマンドにて、次のような感じかと。

health_check_main.sh
$ python health_check_main.py
あなたの体重を入力してください(kg): 55
あなたの身長を入力してください(cm): 160
----------------------------------------
あなたのBMI: 21.5
あなたの体型: 標準です

以上です。

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?