27行目で合計が定義されていないというエラーが表示されます。以前これを修正するために、7行目と12行目にglobalを追加しましたので、17行目に追加しようとしましたが、それでもエラーが表示されます。どのように私はこれを修正することができますどのような考え?私のコードに関するその他のヒントや情報も大変ありがとうございます。私はコーディングに新しいです。私は、PythonPythonの関数内で変数を定義する方法
import math
import sys
print("King's BMI Calculator")
def h():
global height
height=float(input("Please enter student's height in inches:"))
return height
def w():
global weight
weight=float(input("Please enter student's weight in pounds:"))
return weight
def bmi():
global total
total=((str(weight) * 703)/(str(height) * str(height)))
return total
def printbmi():
print(name + "'s BMI Profile")
print("Height:", str(height), "inches")
print("Weight:", str(weight), "lbs")
print("BMI Index:" + str(float(round(total, 1))))
return
def main():
h()
w()
printbmi()
while True:
name = input("Please enter student's name or press 0 to quit:")
if name == "0":
break
main()
に値を格納している、
は、あなたは、どこでも合計を定義していませんこっちで。 27行目は何ですか? –bmi()
を呼び出すためには表示されませんので、この場合はああ、申し訳ありません。私の行番号はとにかくすべて乱されています... –
エラーは... at print( "BMI Index:" + str(float(round、total、1)))) NameError:name 'total'が定義されていません –