Open roberthsu2003 opened 1 month ago
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
except ValueError:
print("格式錯誤")
while True :
stuff = input("還要繼續('q':離開,enter:繼續)嗎")
if stuff == "q":
break
else:
print(stuff.capitalize())
continue
print("應用程式結束")
#計算完成後,問使用者還要繼續('q':離開,enter:繼續)嗎?
while True:
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name} 的 bmi 為 {bmi},為{grade}")
except ValueError:
print("格式錯誤")
stuff = input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")
if stuff == 'q':
break
else:
continue
print("應用程式結束")
import math
while True:
try:
name=str(input('請輸入姓名'))
high=float(input('請輸入身高(cm)'))
highb=high/100
weight=float(input('請輸入體重(kg)'))
except ValueError:
print("格式錯誤")
else:
BMI=round(weight/(highb**(2)),ndigits=2)
print(f'{name}你好:')
print(f'您的BMI值是:{BMI}')
if BMI<18.5:
print('體重:過輕')
elif BMI<24:
print('體重:正常')
elif BMI<27:
print('體重:過重')
elif BMI<30:
print('體重:輕度肥胖')
elif BMI<35:
print('體重:中度肥胖')
else:
print('體重:重度肥胖')
continue0=str(input('是否結束?(輸入q)'))
if continue0=='q':
break
else:
continue
while True:
name=str(input("請輸入姓名[按q會離開]:"))
if name == 'q':
print("應用程式結束")
break
try:
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
except ValueError:
print("格式錯誤")
else:
print(f"{name}的bmi為{bmi},為{grade}")
try:
while True:
name=input("請輸入姓名")
height=float(input('請輸入身高(cm):'))
weight=float(input('請輸入體重(kg):'))
bmi=round(weight/((height*0.01)**2),ndigits=2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
else:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
decide=input("還要繼續嗎?('q':離開,enter:繼續)")
if decide=='q':
break
except ValueError:
print("格式錯誤")
else:
print("應用程式結束")
print("輸入q離開")
while True:
try:
name_input = input("請輸入姓名:")
if name_input.lower() == 'q':
break
name = str(name_input)
height_input = input("請輸入身高(cm):")
if height_input.lower() == 'q':
break
height = float(height_input)
weight_input = input("請輸入體重(kg):")
if weight_input.lower() == 'q':
break
weight = float(weight_input)
bmi = weight / (height * 0.01) ** 2
if bmi < 18.5:
grade = "體重過輕"
elif bmi < 24:
grade = "正常範圍"
elif bmi < 27:
grade = "過重"
elif bmi < 30:
grade = "輕度肥胖"
elif bmi < 35:
grade = "中度肥胖"
else:
grade = "重度肥胖"
print(f"{name} 的 BMI 為 {bmi:.2f}, 屬於 {grade}")
except ValueError:
print("格式錯誤,請輸入正確的數字。")
print("應用結束")
while True:
name=str(input("請輸入姓名:(輸入q再按enter離開)"))
if name=='q':
print("應用程式結束")
break
try:
height=float(input('請輸入身高:'))
weight=float(input('請輸入體重:'))
BMI=round(weight/(height*0.01)**2,ndigits=2)
if BMI<18.5:
grade="過輕"
elif BMI<24:
grade="正常"
elif BMI<27:
grade="過重"
elif BMI<30:
grade="輕度肥胖"
elif BMI<35:
grade="中度肥胖"
elif BMI>=35:
grade="重度肥胖"
print(f"{name}的BMI為{BMI}\n體重:{grade}")
except ValueError:
print("格式錯誤")
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
except ValueError:
print("格式錯誤")
else:
print("應用程式結束")
while True:
stuff = input("請輸入q來決定是否要離開!")
if stuff != "q":
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
else:
break
while True:
name=str(input('請輸入姓名:'))
try:
height=float(input('請輸入身高(cm):'))
weight=float(input('請輸入體重(kg):'))
except ValueError:
print('格式錯誤')
else:
BMI=round(weight/((height*0.01)**2),ndigits=2)
print(f'{name}您好')
print(f'您的BMI值是:{BMI}')
if BMI>=35:
grade='重度肥胖'
elif BMI>=30:
grade='中度肥胖'
elif BMI>=27:
grade='輕度肥胖'
elif BMI>=24:
grade='過重'
elif BMI>=18:
grade='正常'
else:
grade='過輕'
print(f'體重:{grade}')
leave = input("是否要繼續計算?['q':離開,enter:繼續]:")
if leave == 'q':
break
print('應用程式結束!')
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
except ValueError:
print("格式錯誤")
else:
print("應用程式結束")
while True:
stuff = input("請輸入q來決定是否要離開!")
if stuff != "q":
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
else:
break
try:
while True:
name=input("請輸入姓名:")
height=float(input('請輸入身高:'))
weight=float(input('請輸入體重:'))
bmi=round(weight/(((height*0.01))**2),ndigits=2)
if bmi<18.5:
grade="過輕"
elif bmi<24:
grade="正常"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}您好,您的的BMI值為{bmi},體重:{grade}")
answer=input("是否再進行計算?按q會離開,enter繼續")
if answer == 'q':
break
else:
continue
print("應用程式結束")
except ValueError:
print("格式錯誤")
while True:
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name} 的 bmi 為 {bmi},為{grade}")
except ValueError:
print("格式錯誤")
stuff = input("請問是否繼續輸入資料 ('q':離開, 按Enter:繼續)?")
if stuff == 'q':
break
else:
continue
print("應用程式結束!")
while True:
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight/(((height*0.01))**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
except ValueError:
print("格式錯誤")
stuff = input("請問還要繼續('q':離開,enter:繼續)嗎?")
if stuff == "q":
break
else:
continue
print("應用程式結束")
while True: try: name=str(input("please enter your name")) height=float(input('please enter your height')) weight=float(input('please enter your weight')) bmi=weight/(height**2) if bmi<18.5: grade="too thin" elif bmi<24: grade="normal" elif bmi<27: grade="heavy" elif bmi<30: grade="simple heavy" elif bmi<35: grade="normal heavy" else: grade="seriously heavy" print(f"{name} bmi is {bmi},is {grade}") except ValueError: print("format error") stuff = input("please enter next data ('q':quit)")
if stuff == 'q':
break
else:
continue
print("app is end")
try:
while True:
name=input("請輸入姓名")
height=float(input('請輸入身高(cm):'))
weight=float(input('請輸入體重(kg):'))
bmi=round(weight/((height*0.01)**2),ndigits=2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
else:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
decide=input("還要繼續嗎?('q':離開,enter:繼續)")
if decide=='q':
break
except ValueError:
print("格式錯誤")
else:
print("應用程式結束")
while True:
name=str(input('請輸入姓名:'))
try:
h=float(input('請輸入身高cm:'))
if h<=0:
raise Exception
w=float(input('請輸入體重kg:'))
if w<=0:
raise Exception
except Exception:
print('格式錯誤')
else:
BMI=round(w/((h*0.01)**2),ndigits=2)
print(f'{name}你好:')
print(f'你的BMI值為:{BMI}')
if BMI<18.5:
print('體重:過輕')
elif BMI<24:
print('體重:正常')
elif BMI<27:
print('體重:過重')
elif BMI<30:
print('體重:輕度肥胖')
elif BMI<35:
print('體重:中度肥胖')
else:
print('體重:重度肥胖')
stuff = input("請問還要繼續('q':離開,enter:繼續)嗎?:")
if stuff=='q':
break
print('應用程式結束')
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi = round(weight/((height*0.01)**2), ndigits = 2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{grade}")
except ValueError:
print("格式錯誤")
while True:
stuff = input("還要繼續嗎('q':離開,enter:繼續)?")
if stuff == "q":
break
else:
continue
print("應用程式結束")
while True:
try:
name=str(input("請輸入姓名"))
height=float(input('請輸入身高'))
weight=float(input('請輸入體重'))
bmi=weight//((height*0.01)**2)
if bmi<18.5:
grade="體重過輕"
elif bmi<24:
grade="正常範圍"
elif bmi<27:
grade="體重過重"
elif bmi<30:
grade="輕度肥胖"
elif bmi<35:
grade="中度肥胖"
elif bmi>=35:
grade="重度肥胖"
print(f"{name}的bmi為{bmi},為{bmi}")
except ValueError:
print("格式錯誤")
while True :
stuff=input("是否繼續輸入('q':離開,enter:繼續)")
if continue0=='q':
break
else:
continue
修改以下程式碼
- 計算完成後,問使用者還要繼續('q':離開,enter:繼續)嗎?
try: name=str(input("請輸入姓名")) height=float(input('請輸入身高')) weight=float(input('請輸入體重')) bmi=weight/(((height*0.01))**2) if bmi<18.5: grade="體重過輕" elif bmi<24: grade="正常範圍" elif bmi<27: grade="過重" elif bmi<30: grade="輕度肥胖" elif bmi<35: grade="中度肥胖" elif bmi>=35: grade="重度肥胖" print(f"{name}的bmi為{bmi},為{grade}") except ValueError: print("格式錯誤") else: print("應用程式結束")
寫的不錯
修改以下程式碼