roberthsu2003 / __2024_04_17_mon_wed__

Python與AI人工智慧開發入門
25 stars 4 forks source link

請將下面程式,修改一下 #7

Open roberthsu2003 opened 2 months ago

roberthsu2003 commented 2 months ago
截圖 2024-05-06 晚上9 16 54
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}')
chesterXalan commented 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}')

image

MurrayChuang commented 2 months ago
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}')
image
g02170017 commented 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:
        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}')

image

pear60706 commented 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: {round(bmi,ndigits=2)}')
    print(f'您的體重:{result}')
    #您的體重:正常
except Exception as e:
    print(f'錯誤: {e}')

未命名

PercJK commented 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: {round(bmi,ndigits=2)}')
    print (f"您的體重:{result}")
    #您的體重:正常
except Exception as e:
     print(f'錯誤: {e}')

螢幕擷取畫面 2024-05-06 234353 螢幕擷取畫面 2024-05-06 234520

YEZZHUANLE commented 2 months ago

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}") 螢幕擷取畫面 2024-05-07 003030

chihweihan commented 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: {round(bmi,ndigits=2)}')
    print(f"計算結果:您是屬於{result}")

except Exception as e:
    print(f'錯誤: {e}')

image

chiayuben commented 2 months ago
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}')

image

Neillo0514 commented 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: 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}') image

victor1629 commented 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
    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}')

螢幕擷取畫面 2024-05-07 205514

螢幕擷取畫面 2024-05-07 210948

Tony840705 commented 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
    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}')

BMI計算

JamesHungWJ commented 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
    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}')

image

drama554 commented 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:
        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}')

螢幕擷取畫面 2024-05-08 171539

KIOVER998 commented 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: {round(bmi,ndigits=2)}')
    print(f'你的體重:{result}')
except Exception as e:
    print(f'錯誤: {e}')

擷取

ccanna commented 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:
        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}')

image

Vress0 commented 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
    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}')

image

tary159951123 commented 1 month 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}')
except SyntaxError as e:
    print(f'語法錯誤: {e}')
Tina54321 commented 1 month 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
    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}")

image