Open roberthsu2003 opened 2 months ago
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(cm):'))
weight = float(input('請輸入體重(kg):'))
bmi = weight / ((height / 100) ** 2)
print(f'{name}, 您的BMI: {round(bmi, ndigits=2)}')
except Exception as e:
print(f'格式錯誤: {e}')
try:
name:str = input("請輸入姓名:")
height:float = float(input("請輸入身高(cm):")) * 0.01
weight:float = float(input("請輸入體重(kg):"))
BMI = round(weight / (height ** 2), ndigits=2)
print(f"{name},您的BMI:{BMI},BMI正常範圍為18.5~24")
except Exception as error:
print(f"格式錯誤:{error}")
try:
name = input("請輸入姓名")
height = eval(input("請輸入身高(cm)"))
weight = eval(input("請輸入體重(kg)"))
print(f"{name},您的BMI:{weight / (height / 100) ** 2:.2f}")
except Exception as e:
print(f"格式錯誤:{e}")
try:
Name = input('請輸入姓名:')
Height = float(input('請輸入身高(cm):'))
Weight = float(input('請輸入體重(kg):'))
BMI = Weight / (Height/100) ** 2
print(f'{Name},您的BMI為:{round(BMI,ndigits=2)}')
except Exception as e:
print(f'格式錯誤:{e}')
try:
name:str=str(input("請輸入姓名:"))
height:float=float(input("請輸入身高(cm):"))
weight:float=float(input("請輸入體重(kg):"))
BMI =weight/(height/100)**2
print(f"{name},您的BMI{BMI:.2f}")
except Exception as a :
print(f'格式錯誤{a}')
try:
name:str=input('請輸入名字')
weight:str|float=eval(input('請輸入重量(Kg)'))
high:str|float=eval(input('請輸入身高(公分)'))
BMI:str|float=weight/(high/100)**2
print(f'你的名字是{name},體重為{weight},身高為{high},經計算後BMI為{round(BMI,ndigits=1)}')
if BMI>=18.5:
if BMI>=24:
print('你的BMI偏高,可能要減肥了喔')
else:
print('BMI很標準繼續保持')
else:
if BMI <=18.5:
print('你的BMI值偏低,記得多吃點喔')
except Exception as e :
print(f'發生錯誤{e}請重新輸入')
try:
name:str = str(input('請輸入姓名:'))
height:float = float(input('請輸入身高(cm):'))
weight:float = float(input('請輸入體重(kg):'))
bmi = weight / ((height / 100) ** 2)
print(f'{name}, 您的BMI: {round(bmi, ndigits=2)}')
except Exception as e:
print(f'格式錯誤: {e}')
try:
name:str = input("請輸入姓名:")
height:int|float = eval(input("請輸入身高(cm)"))
weight:int|float = eval(input("請輸入體重(kg)"))
BMI:str = weight / (height / 100) ** 2
print(f"{name},您的身高:{height} cm,體重:{weight} kg。\n經計算過後,您的BMI:{round(BMI, ndigits=2)}")
if BMI > 18.5:
if BMI >= 24:
print("要小心囉,「體重過重」了!")
else:
print("恭喜!「健康體重」,要繼續保持!")
else:
print("「體重過輕」,需要多運動,均衡飲食,以增加體能,維持健康!")
except Exception as e:
print(f'輸入內容有誤:{e},請重新輸入。')
想請問要如何知道自己是哪裡輸入錯誤以及輸入的內容?
try:
name = input('請輸入姓名:')
height = float(input('請輸入身高(cm):'))
weight = float(input('請輸入體重(kg):'))
bmi = weight / ((height / 100) ** 2)
print(f'{name}, 您的BMI: {round(bmi, ndigits=2)}')
except Exception as e:
print(f'格式錯誤: {e}')
try:
Name = input('請輸入姓名:')
Height = float(input('請輸入身高(cm):'))
Weight = float(input('請輸入體重(kg):'))
BMI = Weight / (Height/100) ** 2
print(f'{Name},您的BMI為:{round(BMI,ndigits=2)}')
except Exception as e:
print(f'格式錯誤:{e}')
try:
name:str =input('請輸入名字:')
height = float(input('請輸入身高:'))
weight = float(input('請輸入體重'))
BMI = round(weight/((height/100)**2),2)
print(f'{name}的BMI指數為{BMI}')
except Exception as e:
print(f'格是錯誤:{e}')
try:
name = str(input("請輸入姓名"))
height:int|float = int(input("請輸入身高(cm)"))
weight:int|float = int(input("請輸入體重(kg)"))
bmi = weight / ((height/100) **2)
print(f"{name},你的BMI:{round(bmi,ndigits=1)}")
except Exception as e:
print(f"格式錯誤:{e}")
try:
name:str = input('請輸入姓名:')
height:float = float(input('請輸入身高(cm):'))
weight:float = float(input('請輸入體重(kg):'))
BMI = weight / ((height / 100) ** 2)
print(f"{name},你的BMI:{BMI:.2f}")
except Exception as a:
print(f"格式錯誤:{a}")
try:
name = input("請輸入您的姓名")
height = float(input("請輸入您的身高:cm"))
weight = float(input("請輸入您的體重:kg"))
bmi = weight / ((height / 100) * 2)
print(f"{name}您的bmi:{bmi:.2f}")
except Exception as e:
print(f"發生錯誤{e}")
try:
name:str = input("請輸入姓名:")
height:float = float(input("請輸入身高:"))
weight:float = float(input("請輸入體重:"))
print(f"{name},您的BMI:{round(weight/(height/100)**2,ndigits=2)}")
except Exception as e:
print(f"格式錯誤{e}")
try:
name = input("輸入姓名")
h = float(input("請輸入您的身高(cm)"))/100
w = float(input("請輸入您的體重(kg)"))
bmi =round(w/(h*h))
print(bmi)
if bmi <= 18.5:
print("你太輕囉")
if bmi >= 18.5 and bmi <= 25:
print("你的體重正常")
if bmi >= 25:
print("你好肥")
except Exception as error:
print(f'格式錯誤:{error}')
try:
name=input("請輸入您的姓名:")
hieght=eval(input("請輸入您的身高(cm)"))
wieght=eval(input("請輸入您的體重"))
bmi=round(wieght/((hieght/100)**2),ndigits=2)
print(f"{name},您的身高為{hieght},體重為{wieght},經計算BMI為{bmi}")
except Exception as e:
print(f"發生錯誤{e}")
try:
name = input("請輸入姓名")
height = eval(input("請輸入身高(cm)"))
weight = eval(input("請輸入體重(kg)"))
print(f"{name},您的BMI:{weight / (height / 100) ** 2:.2f}")
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)}')
#您的體重:正常
except Exception as e:
print(f'錯誤: {e}')
try:
name = input("請輸入姓名:")
height:int = int(input("請輸入身高(cm):"))
weight:int = int(input("請輸入體重(kg)"))
bmi = round(weight / (height/100)**2, ndigits=2)
print(f"{name},您的BMI值為:{bmi}")
if bmi >=18.5 and bmi <= 24:
print("恭喜!標準體態!")
if bmi >24:
print("建議每周333運動!")
if bmi <18.5:
print ("建議多補充營養食物!")
except Exception as e:
print (f"格式錯誤:{e}")
輸入:
輸出:
錯誤: