0
私はプログラミング初心者でも初心者です。私はここにいくつかのトピックの助けを借りてBMIを計算するプログラムを書いた。PythonでBMIを計算するための効果的なプログラミング
コードのレビュー:私はプログラムで主な機能を3回使用していましたが、私はbmiの式を書くこともやや効率的であると考えています。つまり、floatから変数へのキャストは避けてください。同じコードを効率的に書くことをお勧めします。
また、https://automatetheboringstuff.comからptyhonを学んでいます。もしあなたがpython onlineを学ぶ最良の方法をお勧めしたいのであれば教えてください。コマンドラインを使用して
import re
print('Calculate your body mass index(BMI) today.')
def main():
while True:
myName = input('Enter your name:')
if re.match('^[a-z, A-Z, ,]*$', myName):
print ('Nice to meet you, ' + myName)
return
else:
print ('You should enter a to z letters only!')
if __name__ == "__main__":
main()
def main():
while True:
global height
height = input('Enter your height in cms: ')
if re.match('^[0-9]*$', height):
return
else:
print ('You should enter 0 to 9 letters only!')
if __name__ == "__main__":
main()
def main():
while True:
global weight
weight = input('Enter your weight in kgs: ')
if re.match('^[0-9]*$', weight):
return
else:
print ('You should enter 0 to 9 letters only!')
if __name__ == "__main__":
main()
bmi = round((float (weight)/ (0.0001*float(height)*float(height))), 2)
minIdealWeight = round(18.5*0.0001*float(height)*float(height), 2)
maxIdealWeight = round(25*0.0001*float(height)*float(height), 2)
if 18.5<bmi<25:
print('Your BMI is '+str(bmi)+'.' '\n Maintain your weight, you\'re normal.')
elif bmi<18.5:
print('Your BMI is '+str(bmi)+'.' '\nGain some weight, you\'re underweight.')
print('Your ideal weight is between '+str(minIdealWeight)+' to ' +str(maxIdealWeight)+' kgs.')
else:
print('Your BMI is '+str(bmi)+'.' '\nLoose some weight, you\'re overweight.')
print('Your ideal weight is between '+str(minIdealWeight)+' to ' +str(maxIdealWeight)+' kgs.')
ようこそStackOverflow。良い質問をする方法(https://stackoverflow.com/help/how-to-ask)を見てください。あなたの現在の質問は少し曖昧です。あなたの特定の効率要件は何ですか?ベンチマークのデータとターゲットを表示し、これまでに試したことも示します。それについては、「効率的」とはどういう意味ですか?一般的に、可能な限り具体的な質問をしてください。それは、良い、迅速な答えを得るあなたのチャンスを最大化します。すべてのことを言っているが、この質問は[CodeReview](https://codereview.stackexchange.com/)のほうが良いかもしれない。 –
プログラミングを始めたばかりの方であれば、何か簡単に始めることをお勧めします。あなたが使用しているサイトはOKですが、一歩一歩を踏み出し、非常に基本的なものをマスターする前に、より複雑なものにジャンプしないでください。正規表現は基本以上のものです! –