roberthsu2003 / __2024_07_29_1_3_night__

2024_07_29_1_3_巨匠AI
20 stars 3 forks source link

請將以下程式碼,建立自訂的function #5

Open roberthsu2003 opened 3 weeks ago

roberthsu2003 commented 3 weeks ago

提示:

def get_status_message(bmi:float)->str:
#計算完成後,問使用者還要繼續('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("格式錯誤")
        continue
    stuff = input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")

    if stuff == 'q':
        break

print("應用程式結束")
yinggg32 commented 3 weeks ago
def get_status_message(bmi: float) -> str:
    if bmi < 18.5:
        return "體重過輕"
    elif bmi < 24:
        return "正常範圍"
    elif bmi < 27:
        return "過重"
    elif bmi < 30:
        return "輕度肥胖"
    elif bmi < 35:
        return "中度肥胖"
    else:
        return "重度肥胖"

while True:
    try:
        name = input("請輸入姓名: ")
        height = float(input('請輸入身高(cm): '))
        weight = float(input('請輸入體重(kg): '))
        bmi = weight / ((height * 0.01) ** 2)
        grade = get_status_message(bmi)
        print(f"{name} 的 BMI 為 {bmi:.2f}, 為 {grade}")
    except ValueError:
        print("格式錯誤,請重新輸入數據")
        continue

    stuff = input("請問是否繼續輸入資料 ('q': 離開, 任意鍵: 繼續)? ")

    if stuff == 'q':
        break

print("應用程式結束")
hellno3009 commented 3 weeks ago
def get_status_message(bmi: float) -> str:
    if bmi < 18.5:
        return "體重過輕"
    elif bmi < 24:
        return "正常範圍"
    elif bmi < 27:
        return "過重"
    elif bmi < 30:
        return "輕度肥胖"
    elif bmi < 35:
        return "中度肥胖"
    else:
        return "重度肥胖"

while True:
    try:
        name = input("請輸入姓名: ")
        height = float(input('請輸入身高(cm): '))
        weight = float(input('請輸入體重(kg): '))
        bmi = weight / ((height * 0.01) ** 2)
        grade = get_status_message(bmi)
        print(f"{name} 的 BMI 為 {bmi:.2f}, 為 {grade}")

    except ValueError:
        print("格式錯誤")
        continue

    stuff = input("是否繼續輸入資料?(q: 離開,其他鍵:繼續)")

    if stuff == 'q':
        break

print("程式結束")
72032c commented 3 weeks ago
def bmi(bmi:float)->str:
    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}")

while True:
    name=str(input("請輸入姓名:(輸入q再按enter離開)"))
    if name=='q':
        break
    try:
        height=float(input('請輸入身高:'))
        weight=float(input('請輸入體重:'))
    except ValueError:
        print("格式錯誤")
    BMI=bmi(bmi)

print("應用程式結束")
gloria8395 commented 3 weeks ago
def get_status_message(bmi:float)->str:
    if bmi<18.5:
        return "體重過輕"
    elif bmi<24:
        return "正常範圍"
    elif bmi<27:
        return "過重"
    elif bmi<30:
        return "輕度肥胖"
    elif bmi<35:
        return "中度肥胖"
    elif bmi>=35:
        return "重度肥胖"
while True:
    try:
        name=input("請輸入姓名")
        height=float(input('請輸入身高(cm):'))
        weight=float(input('請輸入體重(kg):'))
        bmi=round(weight/((height*0.01)**2),ndigits=2)
        print(f"{name} 的 bmi 為 {bmi},為{get_status_message(bmi)}")
    except ValueError:
        print("格式錯誤")
        continue
    stuff=input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")
    if stuff=='q':
        break
print("應用程式結束")
WayneChou-bot commented 3 weeks ago
def get_status_message(bmi:float)->str:
    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:
  get_status_message(0)
  stuff = input("請問是否繼續輸入資料 ('q':離開, Enter:繼續)?")
  if stuff == 'q':
    break

print("應用程式結束")
FriendlyLu commented 3 weeks ago
#計算完成後,問使用者還要繼續('q':離開,enter:繼續)嗎?

def get_status_message(bmi:float)->str:
    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="重度肥胖"

    return grade

while True:
    try:
        name=str(input("請輸入姓名"))
        height=float(input('請輸入身高'))
        weight=float(input('請輸入體重'))
        bmi=weight/(((height*0.01))**2)
        print(f"{name} 的 bmi 為 {bmi},為{get_status_message(bmi = bmi)}")
    except ValueError:
        print("格式錯誤")
        continue
    stuff = input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")

    if stuff == 'q':
        break

print("應用程式結束")
Srdell7 commented 3 weeks ago
def get_status_message(bmi)->str:
    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}您好')
    print(f'您的BMI值是:{bmi}')
    print(f'體重:{grade}')
while True:
    try:
        name=str(input("請輸入姓名"))
        height=float(input('請輸入身高'))
        weight=float(input('請輸入體重'))
        bmi=round(weight/((height*0.01)**2),ndigits=2)
    except ValueError:
        print("格式錯誤")
        continue
    get_status_message(bmi)
    stuff = input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")
    if stuff == 'q':
        break
print("應用程式結束")
yawenny commented 3 weeks ago
def get_status_message(bmi:float)->str:
    if bmi<18.5:
            return "體重過輕"
    elif bmi<24:
        return "正常範圍"
    elif bmi<27:
        return "過重"
    elif bmi<30:
        return "輕度肥胖"
    elif bmi<35:
        return "中度肥胖"
    elif bmi>=35:
        return "重度肥胖"

while True:
    try:
        name=str(input("請輸入姓名"))
        height=float(input('請輸入身高'))
        weight=float(input('請輸入體重'))
        bmi=round(weight/(((height*0.01))**2),ndigits=2)
        message = get_status_message(bmi)
        print(f"{name} 的 bmi 為 {bmi},為{message}")
    except ValueError:
        print("格式錯誤")
        continue
    stuff = input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")

    if stuff == 'q':
        break

print("應用程式結束")
Oscar-Lee-20211298 commented 3 weeks ago
def get_status_message(bmi: float) -> str:
    if bmi<18.5:
        return "too thin"
    elif bmi<24:
        return "normal"
    elif bmi<27:
        return "heavy"
    elif bmi<30:
        return "simple heavy"
    elif bmi<35:
        return "normal heavy"
    else:
        return "seriously heavy"

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)
        grade = get_status_message(bmi)
        print(f"{name}  bmi is {bmi},is {grade}")
    except ValueError:
        print("format error")
        continue
    stuff = input("please enter next data ('q':quit)")

    if stuff == 'q':
        break
print("app is end")
grace588 commented 3 weeks ago
def get_status_message(bmi:float)->str:

    if bmi<18.5:
        return"體重過輕"
    elif bmi<24:
        return"正常範圍"
    elif bmi<27:
        return"過重"
    elif bmi<30:
        return"輕度肥胖"
    elif bmi<35:
        return"中度肥胖"
    elif bmi>=35:
        return"重度肥胖"

while True:
    try:
        name=input("請輸入姓名")
        height=float(input('請輸入身高'))
        weight=float(input('請輸入體重'))
        bmi=round(weight/((height*0.01)**2),ndigits=2)
        print(f"{name} 的 bmi 為 {bmi},為{get_status_message(bmi)}")

    except ValueError:
        print("格式錯誤")
        continue
    stuff = input("請問是否繼續輸入資料 ('q':離開,任意鍵:繼續)?")

    if stuff == 'q':
        break

print("應用程式結束")      
Imbradley1213 commented 3 weeks ago
def status():
        if BMI<18.5:
            return('過輕')
        elif BMI<24:
            return('正常')
        elif BMI<27:
            return('過重')
        elif BMI<30:
            return('輕度肥胖')
        elif BMI<35:
            return('中度肥胖')
        else:
            return('重度肥胖') 
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('格式錯誤')
        continue
    else:
        BMI=round(w/((h*0.01)**2),ndigits=2)
        print(f'{name}你好:')
        print(f'你的BMI值為:{BMI}')
        print(f'你的體重為:{status()}')
    stuff = input("請問還要繼續('q':離開,enter:繼續)嗎?:")
    if stuff=='q':
        break
print('應用程式結束')
kxyzqo commented 3 weeks ago
def get_status_message(bmi:float)->str:
    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:
    get_status_message(bmi)
    stuff = input("請問是否繼續輸入資料 ('q': 離開, 任意鍵: 繼續)? ")
    if stuff == 'q':
        break

print("應用程式結束")
SophiaSu0925 commented 3 weeks ago
def get_status_message(bmi:float) -> str:
    if bmi < 18.5:
        return "體重過輕"
    elif bmi < 24:
        return "正常範圍"
    elif bmi < 27:
        return "過重"
    elif bmi < 30:
        return "輕度肥胖"
    elif bmi < 35:
        return "中度肥胖"
    else:
        return "重度肥胖"
while True:
  try:
    name=str(input("請輸入姓名"))
    height=float(input('請輸入身高'))
    weight=float(input('請輸入體重'))
    bmi = round(weight/((height*0.01)**2), ndigits = 2)
    status = get_status_message(bmi)
    print(f"{name}的BMI為{bmi},為{status}")
  except ValueError:
    print("格式錯誤")
  stuff = input("還要繼續嗎('q':離開,enter:繼續)?")
  if stuff == "q":
    break
  else:
    continue

print("應用程式結束")