roberthsu2003 / __2024_04_17_mon_wed__

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

請使用pyInputPlus修改以下程式 #8

Open roberthsu2003 opened 2 months ago

roberthsu2003 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)}')
except Exception as e:
    print(f'錯誤: {e}')
chesterXalan commented 2 months ago
import pyinputplus as pyip

name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min=120, max=230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min=40, max=170)

bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {bmi:.2f}')

image

MurrayChuang commented 2 months ago
import pyinputplus as pyip

name = pyip.inputStr('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min = 120, max = 230)     
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min = 40, max = 170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')
image
chihweihan commented 2 months ago
import pyinputplus as pyip

name = input("請輸入姓名:")
height = pyip.inputFloat("請輸入身高(120~230)(cm):",min=120,max=230)
weight = pyip.inputFloat("請輸入體重(40~170)(kg):",min=40,max=170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')

image

chiayuben commented 2 months ago
import pyinputplus as pyip
try:
    name = input('請輸入姓名:')
    high = pyip.inputFloat('請輸入身高(120~230)(cm):',min=120,max=230) 
    weight = pyip.inputFloat('請輸入體重(40~170)(kg):',min=40,max=170)
    bmi = weight /( high / 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
import pyinputplus as pyip

name = input("請輸入姓名:")
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min = 120, max = 230)     
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min = 40, max = 170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')

image

Tony840705 commented 2 months ago
import pyinputplus as pyip

name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min=120, max=230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min=40, max=170)

bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {bmi:.2f}')

BMI計算可輸出錯誤訊息

victor1629 commented 2 months ago
import pyinputplus as pyip
name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):',min=120,max=230)
print(f'您的身高{height}')
weight = pyip.inputFloat('請輸入體重(40~170)(kg):',min=40,max=170)
print(f'您的體重{weight}')
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')   

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

Tina54321 commented 2 months ago
import pyinputplus as pyip

name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):',min=120,max=230) 
weight = pyip.inputFloat('請輸入體重(40~170)(kg):',min=40,max=170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')

image

drama554 commented 2 months ago
import pyinputplus as pyip

name = pyip.inputStr('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min = 120, max = 230)     
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min = 40, max = 170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')

![Uploading 螢幕擷取畫面 2024-05-08 181421.png…]()

KIOVER998 commented 2 months ago
import pyinputplus as pyip

name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(120~230)(cm):', min=120, max=230)
weight = pyip.inputFloat('請輸入體重(40~170)(kg):', min=40, max=170)

bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {bmi:.2f}')

擷取

PercJK commented 2 months ago
import pyinputplus as pyip

name = input('請輸入姓名:')
height = pyip.inputFloat('請輸入身高(cm))',min=120,max=230)
weight = pyip.inputFloat('請輸入體重(kg)',min=40,max=170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')

Lesson6 3

ccanna commented 2 months ago
import pyinputplus as pyip

name = input('請輸入姓名:')

height = pyip.inputFloat("請輸入身高(cm):", min= 120, max=230)
weight = pyip.inputFloat("請輸入體重(kg):", min= 40, max= 170)
bmi = weight / (height / 100) ** 2
print(f'{name}, 您的BMI: {round(bmi,ndigits=2)}')

image image