Open roberthsu2003 opened 1 month ago
import pyinputplus as pyip
def calc_bmi(height: float, weight: float) -> float:
return weight / (height / 100) ** 2
def get_status(bmi: float) -> str:
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = input('請輸入姓名: ')
height = pyip.inputFloat('請輸入身高(120~230)(cm): ', min=120, max=230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg): ', min=40, max=170)
bmi = calc_bmi(height, weight)
status = get_status(bmi)
print(f'\n{name}, 您的BMI: {bmi:.2f}')
print(f'您的體重: {status}')
import pyinputplus as pyip
def bmi(weight: float, height: float) -> float:
return weight / (height / 100) ** 2
def get_status(bmi: float) -> str:
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(cm):', min = 1, max = 300)
weight = pyip.inputFloat('請輸入體重(kg):', min = 1, max = 500)
bmi_value = bmi(weight, height)
print(f'{name}, 您的BMI: {bmi_value:.2f}')
print(f'{name}, 您的體重: {get_status(bmi_value)}')
import pyinputplus as pyip
def bmi(weight: float, height: float) -> float:
return weight / (height / 100) ** 2
def get_status(bmi: float) -> str:
if bmi < 18.5:
result = '體重過輕'
elif bmi < 24:
result = '體重正常'
elif bmi < 27:
result = '體重過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
try:
name = input('請輸入姓名:');
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min = 120, max = 230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min = 40, max = 170)
bmi_value = bmi(weight, height)
print(f'您的身高為{height}公分')
print(f'您的體重為{weight}公斤')
print(f'{name}, 您的BMI為:{bmi_value:.2f}')
print(f'{name}, 您屬於:{get_status(bmi_value)}')
except Exception as e:
print(f'格式錯誤:{e}')
import pyinputplus as pyip
name = pyip.inputStr("請輸入姓名:")
height = pyip.inputFloat("請輸入身高(cm):")
weight = pyip.inputFloat("糗輸入體重(kg):")
def bmi(height:float,weight:float):
return weight / (height / 100) ** 2
def get_status(bmi:float):
if bmi < 18.5:
result = "體重過輕"
elif bmi < 24:
result = "正常範圍"
elif bmi < 27:
result = "體重過重"
elif bmi < 30:
result = "輕度肥胖"
elif bmi < 35:
result = "中度肥胖"
else:
result = "重度肥胖"
return result
BMI = bmi(height,weight)
print(f"{name},您的BMI:{BMI}")
print(f"{name},您屬於:{get_status(BMI)}")
import pyinputplus as pyip
def bmi (high:float,weight:float)->float:
return float(weight / (high / 100) ** 2)
def status(bmi: float|int) -> str:
if bmi<18.5 :
result='體重過輕'
elif bmi>=18.5 and bmi<24:
result='BMI正常'
elif bmi>=24 and bmi<27:
result='過重'
elif bmi<=27 and bmi<30:
result='輕度肥胖'
elif bmi<=30 and bmi<35:
result='中度肥胖'
else:
result='重度肥胖'
return result
def BMT_count():
name = input('請輸入姓名:')
high = pyip.inputFloat('請輸入身高(50~230cm)',min=50,max=230)
print(high)
weight=pyip.inputFloat('請輸入體重(30~250Kg)',min=30,max=250)
print(weight)
BMI=bmi(high,weight)
status(BMI)
print(f'你的身高為{high},體重為{weight},你的BMI為{BMI:.2f},你的狀態為:{status(BMI)}')
while True:
BMT_count()
play_again=pyip.inputYesNo('還要下一位量測嗎?(y,n)\n')
if play_again=='no':
break
print('量測結束\n')
import pyinputplus as py
a = 0
b = 0
def bmi(a: float | int, b: float | int) -> float | int:
a = py.inputFloat('\n請輸入身高(cm):', greaterThan=0); print(f'{a}', end=' ')
b = py.inputNum('\n請輸入體重(kg):', greaterThan=0); print(f'{b}', end=' ')
return b / (0.01 * a) ** 2
def get_status(bmi: float | int) -> str:
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name = py.inputStr("請輸入姓名:"); print(f'{name}', end=' ')
BMI = bmi(a,b)
status = get_status(BMI)
print(f'\n{name},您的BMI:{BMI:.2f},為{status}')
import pyinputplus as pyip
def bmi(weight:float, height:float)->float:
return round(weight / (height/100)**2, ndigits=2)
def get_status(bmi:float)->str:
if bmi <18.5:
remind = '體重過輕'
elif bmi >=18.5 and bmi <24:
remind = '正常體重'
elif bmi >=24 and bmi <27:
remind = '體重過重'
elif bmi >=27 and bmi <30:
remind = '輕度肥胖'
elif bmi >=30 and bmi <35:
remind = '中度肥胖'
else:
remind = '重度肥胖'
return remind
name = pyip.inputStr("請輸入姓名:")
height = pyip.inputFloat("請輸入身高(cm):")
weight = pyip.inputFloat("請輸入體重(kg):")
bmi_count= bmi(weight, height)
print(f"{name},您的BMI值為:{bmi_count}")
print(f"您目前:{get_status(bmi_count)}")
import pyinputplus as pyip
def calc_bmi(height: float, weight: float) -> float:
return weight / (height / 100) ** 2
def get_status(bmi: float) -> str:
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name:str = input('請輸入姓名: ')
height:float = pyip.inputFloat('請輸入身高(120~230)(cm): ', min=120, max=230)
weight:float = pyip.inputFloat('請輸入體重(40~170)(kg): ', min=40, max=170)
bmi:float = calc_bmi(height, weight)
status:str = get_status(bmi)
print(f'\n{name}, 您的BMI: {bmi:.2f}')
print(f'您的體重: {status}')
def calc_bmi(height:float,weight:float)->float:
return weight / (height / 100) ** 2
def get_status (bmi:float)->str:
if bmi < 18.5:
result="過輕"
elif bmi <24:
result="正常範圍"
elif bmi <27:
result="過重"
elif bmi <30:
result="輕度肥胖"
elif bmi <35:
result="中度肥胖"
else:
bmi >=35
result="重度肥胖"
return result
import pyinputplus as pyip
name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):',min=120,max=230)
print(f'您的身高{height}')
weight = pyip.inputFloat('請輸入體重(40~170)(kg):',min=40,max=170)
print(f'您的體重{weight}')
bmi:float=calc_bmi(height,weight)
status:str=get_status(bmi)
print(f'{name}, 您的BMI:{bmi:.2f}')
print(f'{name}, 您的體重:{status}')
import pyinputplus as pyip
def calc_bmi(height: float, weight: float) -> float:
return weight / (height / 100) ** 2
def get_status(bmi: float) -> str:
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
return result
name:str = input('請輸入姓名: ')
height:float = pyip.inputFloat('請輸入身高(120~230)(cm): ', min=120, max=230)
weight:float = pyip.inputFloat('請輸入體重(40~170)(kg): ', min=40, max=170)
bmi:float = calc_bmi(height, weight)
status:str = get_status(bmi)
print(f'\n{name}, 您的BMI: {bmi:.2f}')
print(f'您的體重: {status}')
輸入:
請使用自訂的function
輸出:
錯誤: