roberthsu2003 / __2024_07_29_1_3_night__

2024_07_29_1_3_巨匠AI
20 stars 3 forks source link

請修改以下程式碼,增加計算完後,問使用者是否要離開程式 #4

Open roberthsu2003 opened 1 month ago

roberthsu2003 commented 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("格式錯誤")
else:
    print("應用程式結束")
yinggg32 commented 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("應用程式結束")
FriendlyLu commented 1 month ago
#計算完成後,問使用者還要繼續('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("應用程式結束")
patrick11330619 commented 1 month ago
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
Jonas-0819 commented 1 month ago
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}")
gloria8395 commented 1 month ago
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("應用程式結束")
hellno3009 commented 1 month ago
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("應用結束")
72032c commented 4 weeks ago
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("格式錯誤")
handsomeyoxi commented 4 weeks 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("格式錯誤")
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
Srdell7 commented 3 weeks ago
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('應用程式結束!')
aa854268 commented 3 weeks 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("格式錯誤")
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
yawenny commented 3 weeks ago
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("格式錯誤")
WayneChou-bot commented 3 weeks ago
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("應用程式結束!")
kxyzqo commented 3 weeks ago
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("應用程式結束")
Oscar-Lee-20211298 commented 3 weeks ago

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")

grace588 commented 3 weeks ago
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("應用程式結束")
Imbradley1213 commented 3 weeks ago

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('應用程式結束')
SophiaSu0925 commented 3 weeks ago
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("應用程式結束")
teddy-wz commented 3 weeks ago
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
roberthsu2003 commented 3 weeks ago

修改以下程式碼

  • 計算完成後,問使用者還要繼續('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("應用程式結束")

寫的不錯