Open roberthsu2003 opened 2 months ago
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height < 120 or height > 230:
raise Exception('身高必須大於120同時小於230')
weight = float(input('請輸入體重(40~170)(kg):'))
if weight < 40 or weight > 170:
raise Exception('體重必須大於40同時小於170')
bmi = weight / (height / 100) ** 2
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
print(f'{name}, 您的BMI: {bmi:.2f}')
print(f'您的體重: {result}')
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(cm):'))
if height < 120 or height > 230:
raise Exception("身高必須大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight < 40 or weight > 170:
raise Exception("體重必須大於40同時小於170")
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
print (f"您的體重:{result}")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
if bmi<18.5:
print("體重過輕")
elif bmi>=18.5 and bmi<24:
print("正常範圍")
elif bmi>=24 and bmi<27:
print("過重")
elif bmi>=27 and bmi<30:
print("輕度肥胖")
elif bmi>=30 and bmi<35:
print("中度肥胖")
else:
print("重度肥胖")
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
#您的體重:正常
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
if bmi<18.5:
result = '過輕'
elif bmi<24:
result = '正常'
elif bmi<27:
result = '過重'
elif bmi<30:
result = '輕度肥胖'
elif bmi<35:
result = '中度肥胖'
else:
result = '重度肥胖'
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
print(f'您的體重:{result}')
#您的體重:正常
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
if bmi<18.5:
result = '體重過輕'
elif bmi<24:
result = '正常'
elif bmi<27:
result = '過重'
elif bmi<30:
result = '輕度肥胖'
elif bmi<35:
result = 'ˋ中度肥胖'
else:
result = '重度肥胖'
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
print (f"您的體重:{result}")
#您的體重:正常
except Exception as e:
print(f'錯誤: {e}')
try: name = str(input("請輸入姓名")) height:int|float = int(input("請輸入身高(cm)")) if height <120 or height >230: raise Exception("身高必須大於120同時小於230")
weight:int|float = int(input("請輸入體重(kg)"))
if weight <40 or weight >170:
raise Exception("體重必須大於40同時小於170")
bmi = weight / ((height/100) **2)
if bmi<18.5:
a=("過輕")
elif 18.5<=bmi<24:
a=("正常")
elif 24<=bmi<27:
a=("過重")
elif 27<=bmi<30:
a=("輕度肥胖")
elif 30<=bmi<35:
a=("中度肥胖")
elif 35>=bmi:
a=("重度肥胖")
print(f"{name},你的BMI:{round(bmi,ndigits=1)}")
print(f"你的體重:{a}")
except SyntaxError as e:
print(f"格式錯誤:{e}")
except Exception as e:
print(f"錯誤:{e}")
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
if bmi < 18.5:
result = "體重過輕"
elif bmi < 24:
result = "正常範圍"
elif bmi < 27:
result = "體重過重"
elif bmi < 30:
result = "輕度肥胖"
elif bmi < 35:
result = "中度肥胖"
else:
result = "重度肥胖"
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
print(f"計算結果:您是屬於{result}")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
high = float(input('請輸入身高(120~230)(cm):'))
if high<120 or high>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
print(f'你的名字是{name},體重為{weight},身高為{high},經計算後BMI為{round(bmi,ndigits=1)}')
if bmi<18.5 :
print('體重過輕')
elif bmi>=18.5 and bmi<24:
print('BMI正常')
elif bmi>=24 and bmi<27:
print('過重')
elif bmi<=27 and bmi<30:
print('輕度肥胖')
elif bmi<=30 and bmi<35:
print('中度肥胖')
else:
print('重度肥胖')
#您的體重:正常
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
if bmi<18.5:
print("體重過輕")
elif bmi>=18.5 and bmi<24:
print("正常範圍")
elif bmi>=24 and bmi<27:
print("過重")
elif bmi>=27 and bmi<30:
print("輕度肥胖")
elif bmi>=30 and bmi<35:
print("中度肥胖")
else:
bmi>=35
print("重度肥胖")
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi= weight / (height / 100) ** 2
print(f'{name}, 您的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:
bmi >=35
print("重度肥胖")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi= weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
if bmi<18.5:
print("體重過輕")
elif bmi >=18.5 and bmi <24:
print("正常範圍")
elif bmi >=24 and bmi <27:
print("過重")
elif bmi >=27 and bmi <30:
print("輕度肥胖")
elif bmi >=30 and bmi <35:
print("中度肥胖")
else:
bmi >=35
print("重度肥胖")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
print(f'{name},您的BMI:{round(bmi,ndigits=2)}')
if bmi < 18.5:
result="體重過輕"
elif bmi <24:
result="體重正常"
elif bmi < 27:
result="體重過重"
elif bmi < 30:
result="輕度肥胖"
elif bmi < 35:
result="中度肥胖"
else:
result="重度肥胖"
print(f"您的體重:{result}")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
if bmi<18.5:
print("體重過輕")
elif bmi>=18.5 and bmi<24:
print("體重正常")
elif bmi >=24 and bmi<27:
print("體重過重")
elif bmi >=27 and bmi<30:
print("輕度肥胖")
elif bmi >=30 and bmi<35:
print("中度肥胖")
else:
print("重度肥胖")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名')
height = float(input('請輸入身高(120~230)(cm):'))
if height < 120 or height > 230:
raise Exception('身高必須大於120同時小於230')
weight = float(input('請輸入體重(40~170)(kg):'))
if weight < 40 or weight > 170:
raise Exception('體重必須大於40同時小於170')
bmi = weight / (height / 100) ** 2
if bmi < 18.5:
print('體重過輕')
elif bmi >= 18.5 and bmi < 24:
print('正常範圍')
elif bmi >= 24 and bmi < 27:
print('過重')
elif bmi >= 27 and bmi < 30:
print('輕度肥胖')
elif bmi >= 30 and bmi < 35:
print('中度肥胖')
elif bmi >= 35:
print('重度肥胖')
print(f'{name}, 你的BMI:{round(bmi,ndigits=2)}')
except Exception as e:
print(f'錯誤:{e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
if bmi<18.5:
result = '過輕'
elif bmi<24:
result = '正常'
elif bmi<27:
result = '過重'
elif bmi<30:
result = '輕度肥胖'
elif bmi<35:
result = '中度肥胖'
else:
result = '重度肥胖'
print(f'{name}, 你的BMI: {round(bmi,ndigits=2)}')
print(f'你的體重:{result}')
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
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 = '重度肥胖'
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)},{remind}')
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
if bmi < 18.5:
print("體重過輕")
elif 18.5 <= bmi <24:
print("正常")
elif 24 <= bmi <27:
print("過重")
elif 27 <= bmi < 30:
print("輕度肥胖")
elif 30 <= bmi < 35:
print("中度肥胖")
else :
print("重度肥胖")
except Exception as e:
print(f'錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height < 120 or height > 230:
raise Exception('身高必須大於120同時小於230')
weight = float(input('請輸入體重(40~170)(kg):'))
if weight < 40 or weight > 170:
raise Exception('體重必須大於40同時小於170')
bmi = weight / (height / 100) ** 2
if bmi < 18.5:
result = '過輕'
elif bmi < 24:
result = '正常'
elif bmi < 27:
result = '過重'
elif bmi < 30:
result = '輕度肥胖'
elif bmi < 35:
result = '中度肥胖'
else:
result = '重度肥胖'
print(f'{name}, 您的BMI: {bmi:.2f}')
print(f'您的體重: {result}')
except Exception as e:
print(f'錯誤: {e}')
except SyntaxError as e:
print(f'語法錯誤: {e}')
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(120~230)(cm):'))
if height<120 or height>230:
raise Exception("身高必需大於120同時小於230")
weight = float(input('請輸入體重(40~170)(kg):'))
if weight<40 or weight>170:
raise Exception("體重必需大於40同時小於170")
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {bmi:.2f}')
#您的體重:正常
except Exception as e:
print(f'錯誤: {e}')
else:
if bmi < 18.5:
result = "過輕"
elif bmi < 24:
result = "正常"
elif bmi < 27:
result = "過重"
elif bmi < 30:
result = "輕度肥胖"
elif bmi < 35:
result = "中度肥胖"
else:
result = "重度肥胖"
print(f"您的體重:{result}")