roberthsu2003 / __2024_05_05_sunday__

AI 人工智慧開發入門_python
29 stars 2 forks source link

計算BMI #11

Open roberthsu2003 opened 2 months ago

roberthsu2003 commented 2 months ago

輸入:

輸出:

截圖 2024-05-12 下午4 46 26 截圖 2024-05-19 下午3 30 25
eddie3256 commented 2 months ago
import pyinputplus as pypi

name = pypi.inputStr("請輸入您的姓名: ")
print(name)
height = pypi.inputInt("請輸入您的身高(cm): ", min=50, max=250)
print(height)
weight = pypi.inputInt("請輸入您的體重(kg): ", min=0, max=200)
print(weight)

BMI = weight / (height / 100) ** 2
if BMI < 18.5:
    rate = "過輕"
elif BMI < 24:
    rate = "正常"
elif BMI < 27:
    rate = "過重"
elif BMI < 30:
    rate = "輕度肥胖"
elif BMI < 35:
    rate = "中度肥胖"
else:
    rate = "重度肥胖"

print(f"您的姓名為 {name}\n您的BMI值為 {BMI}\n您屬於 {rate} 範圍")

image

minfoung commented 2 months ago
import pyinputplus as pypi

name = pypi.inputStr("請輸入您的姓名: ")
print(name)
height = pypi.inputInt("請輸入您的身高(cm): ", min=50, max=250)
print(height)
weight = pypi.inputInt("請輸入您的體重(kg): ", min=0, max=200)
print(weight)

BMI = weight / (height / 100) ** 2
if BMI < 18.5:
    rate = "過輕"
elif BMI < 24:
    rate = "正常"
elif BMI < 27:
    rate = "過重"
elif BMI < 30:
    rate = "輕度肥胖"
elif BMI < 35:
    rate = "中度肥胖"
else:
    rate = "重度肥胖"

print(f"您的姓名為 {name}\n您的BMI值為 {BMI}\n您屬於 {rate} 範圍")

image

jonathan-sean commented 2 months ago

Code:

# BMI 計算, refer to https://toolboxtw.com/zh-TW/calculator/bmi
# BMI = weight(kg) / height(m)^2

import pyinputplus as pyip

INPUT_TRY = 3

print("BMI 計算,請輸入")
# Exception handling refer to https://docs.python.org/3/tutorial/errors.html
try:
    # Input user information, include name, height and weight
    name = pyip.inputStr("姓名: ", limit=INPUT_TRY)
    height = pyip.inputFloat("身高(公分): ", min=0, limit=INPUT_TRY)
    weight = pyip.inputFloat("體重(公斤): ", min=0, limit=INPUT_TRY)

    # Calculate BMI and get result
    bmi = weight / (height / 100)**2
    if bmi < 18.5:
        result = "過輕"
    elif bmi >= 18.5 and bmi < 24:
        result = "正常"
    elif bmi >= 24 and bmi < 27:
        result = "過重"
    elif bmi >= 27 and bmi < 30:
        result = "輕度肥胖"
    elif bmi >= 30 and bmi < 35:
        result = "中度肥胖"
    else:
        result = "重度肥胖"

    # Output user information, BMI and result
    print(f"\n{name} - 身高: {height}cm,體重: {weight}Kg, BMI: {round(bmi, 2)}")
    print(f"你的體重{result}")
except Exception as e:
    print(f"EXCEPTION - {type(e)}")

Result: image

sanchangj commented 2 months ago
name=input("請輸入姓名:")
height=float(input("請輸入身高(cm):"))
weight= float(input("請輸入體重(kg):"))

bmi=weight/(height/100)**2

print(f"姓名:{name}")
print(f"你的身高:{height}")
print(f"你的體重:{weight}")
print(f"你的BMI:{round(bmi,ndigits=2)}")
if bmi < 18.5:
    print("你的體重過輕")
elif bmi < 24:
    print("你的體重正常")
elif bmi < 27:
    print("你的體重過重")
elif bmi < 30:
    print("你的體重輕度肥胖")
elif bmi < 35:
    print("你的體重中度肥胖")
else:
    print("你的體重種度肥胖")

螢幕擷取畫面 2024-05-20 013853

charlywang11 commented 2 months ago

計算BMI值

import pyinputplus as pypi

name = pypi.inputStr("請輸入您的姓名:")
print(name)
height = pypi.inputInt("請輸入您的身高(cm):",min=1)
print(height)
weight = pypi.inputInt("請輸入您的體重(kg):",min=1)
print(weight)

bmi = weight / (height/100) ** 2

if bmi < 18.5:
    state = "過輕"
elif bmi < 24:
    state = "正常"
elif bmi < 27:
    state = "過重"
elif bmi < 30:
    state = "輕度肥胖"
elif bmi < 35:
    state = "中度肥胖"
else:
    state = "重度肥胖"

print("------------")
print(f"您的姓名是:{name}")
print(f"您的BMI值:{round(bmi, ndigits=2)}")
print(f"您的體重:{state}")

lesson5_練習

OrbAkatsuki commented 2 months ago

BMI計算作業

import pyinputplus as pypi

name = pypi.inputStr("請輸入您的姓名: ")
print(name)
cm = pypi.inputInt("請輸入您的身高(cm): ",min=0,max=300)
print(cm)
kg = pypi.inputInt("請輸入您的體重(kg): ",min=0,max=300)
print(kg)
bmi = kg / (cm/100) ** 2
print(f"您的BMI值為: {bmi}")
if bmi >= 35:
    result = "重度肥胖"
elif bmi >= 30:
    result = "中度肥胖"
elif bmi >= 27:
    result = "輕度肥胖"
elif bmi >= 24:
    result = "過重"
elif bmi >= 18.5:
    result = "正常"
else:
    result = "過輕"
print(f"您的姓名是: {name}")
print(f"您的BMI值: {round(bmi,ndigits=0)}")
print(f"您的體重: {result}")

image

shadow40744398 commented 2 months ago
import pyinputplus as pypi

name =  pypi.inputStr("請輸入你的名字:")
height = pypi.inputFloat("請輸入你的身高(cm):",min=50,max=250)
weight = pypi.inputFloat("請輸入你的體重(kg):",min=0,max=200)
bmi = float(round(weight / ((height/100)**2),ndigits=2))
if bmi < 18.5:
    rate = "過輕"
elif bmi < 24:
    rate = "正常"
elif bmi < 27:
    rate = "過重"
elif bmi < 30:
    rate = "輕度肥胖"
elif bmi < 35:
    rate = "中度肥胖"
else:
    rate = "重度肥胖"

print(f"\n名字:{name},\n身高:{height},\n體重: {weight},\nBMI:{bmi},\n你屬於{rate}範圍")

BMI

mimionana commented 2 months ago
name = input("請輸入您的姓名")

hight = float (input("請輸入您的身高(cm):"))

weight = float (input("請輸入您的體重(kg):"))

BMI = float(weight/(hight/100)**2)

if  BMI<18.5:
  range="過輕"
elif BMI<24:
  range="正常"
elif BMI<27:
  range="過重"
elif BMI<30:
  range="輕度肥胖"
elif BMI<35:
  range="中度肥胖"
else:
  range="重度肥胖"

print(f"您的姓名是:{name}")
print(f"您的BMI值:{round(BMI,ndigits=2)}")
print(f"您的身體質量指數:{range}")
螢幕擷取畫面 2024-05-25 174605 螢幕擷取畫面 2024-05-25 174639
GraceWCH commented 2 months ago
name = input("請輸入您的姓名") 
height = float(input("請輸入您的身高(cm)"))
weight = float(input("請輸入您的體重(kg)"))

BMI = float(weight/(height/100)**2)
if BMI < 18.5: 
    value = "過輕"
elif BMI > 18.5 and BMI < 24:
    value = "正常"
elif BMI < 27:
    value = "過重"
elif BMI < 30:
    value = "輕度肥胖"
elif BMI < 35:
    value = "中度肥胖"
else:
    value = "重度肥胖"

print(f"您的姓名是:{name}")
print(f"您的BMI值是:{round(BMI,ndigits=1)}")
print(f"您的體重:{value}")
截圖 2024-05-25 下午8 33 10
bess122428 commented 2 months ago

以下是我的程式

name = input("Please enter your name")
height = float(input("Please enter your height(cm):"))
weight = float(input("Please enter your weight(kg):"))

bmi = weight / (height/100) **2
if bmi < 18.5:
    rate = "UnderWeight!"
elif bmi < 24:
    rate = "Normal Weight!"
elif bmi < 27:
    rate = "Too Heavy!"
elif bmi < 30:
    rate = "Mild Obesity!"
elif bmi < 35:
    rate = "Moderately Obese!"
else:
    rate = "Severe Obesity!"
print(f"Your name is {name}")
print(f"Your height is {height} cm")
print(f"Your weight is {weight} kg")
print(f"Your BMI value is {round(bmi,ndigits = 2)}")
print(f"Your BMI range is {rate}.")

BMI range

EdwardHsu0212 commented 2 months ago

計算BMI

import pyinputplus as pypi

name = pypi.inputStr("請輸入您的姓名: ")
print(name)
height = pypi.inputInt("請輸入您的身高(cm): ", min=50, max=250)
print(height)
weight = pypi.inputInt("請輸入您的體重(kg): ", min=0, max=200)
print(weight)

BMI = weight / (height / 100) ** 2
if BMI < 18.5:
    rate = "過輕"
elif BMI < 24:
    rate = "正常"
elif BMI < 27:
    rate = "過重"
elif BMI < 30:
    rate = "輕度肥胖"
elif BMI < 35:
    rate = "中度肥胖"
else:
    rate = "重度肥胖"

print(f"您的姓名為 {name}\n您的BMI值為 {BMI}\n您屬於 {rate} 範圍")
截圖 2024-05-31 下午2 19 56