10/14Python實體課 ``` """ 下面的程式可以讓我們得到使用者的BMI data=input('請輸入姓名_性別_身高_體重') #利用input獲取計算使用者BMI所需數據如:身高、體重等。 name=data[0:3] #取出input字串最後顯示姓名所需字串前三個字,拿0到3。 sex=data[4:6] #取出input字串最後顯示性別所需字串第4或5個字,拿4到6。 height=int(data[6:10]) #取出input字串最後顯示以及計算BMI所需字串第6到8或9個字,拿6到10。 weight=int(data[10:14]) #取出input字串最後顯示以及計算BMI所需字串第10到12或13個字,拿6到14。 BMI=(weight/(height/100)**2) #利用上方取出字串的height和weight套入BMI計算公式得出使用者的BMI print(f'您好{name}!\n您的性別:{sex}\n您的身高:{height}\n您的體重:{weight}\n您的BMI指數為:{BMI}') #最後利用上方所取出個數值顯示出使用者的姓名、性別、身高、體重還有BMI,並分行顯示。 ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up