【发布时间】:2021-02-28 00:13:42
【问题描述】:
我的代码有些问题。我不确定它有什么问题。谢谢
if mNewCal or fNewCal < 1200:
NameError:未定义名称“mNewCal”
对不起,如果格式有点奇怪,堆栈溢出让它变得很奇怪。
gender = int(input("enter your gender as a number from the following \n Male: 1 \n Female: 2 \n " ))
height = int(input("Please enter your height in inches: "))
age = int(input("Please enter your age: "))
weight = int(input("Enter your weight in lbs: "))
exercise = int(input("How much exercise do you do during the week (enter number) \n little to no: 1 \n light: 2 \n moderate: 3 \n heavy: 4 \n "))
if gender == 1:
mBMR = 66 + (6.3 * weight) + (12.9 * height) - (6.8 * age)
elif gender == 2:
fBMR = 655 + (4.3 * weight) + (4.7 * height) - (4.7 * age)
if gender == 1:
if exercise == 1:
cal = mBMR * 1.2
elif exercise == 2:
cal = mBMR * 1.375
elif exercise == 3:
cal = mBMR * 1.55
elif exercise == 4:
cal = mBMR * 1.8
else:
if exercise == 1:
cal = fBMR * 1.2
elif exercise == 2:
cal = fBMR * 1.375
elif exercise == 3:
cal = fBMR * 1.55
elif exercise == 4:
cal = fBMR * 1.8
if gender == 1:
mTotalCal = mBMR * 1.2
#print(mTotalCal)
else:
fTotalCal = fBMR * 1.2
# print(fTotalCal)
looseWeight = str(input("do you want to loose weight? if yes, enter Y: \n if no enter N: \n "))
if looseWeight == "Y":
yesWeight = int(input("How much weight do you want to loose (lbs) ? "))
else:
print("thank you for using Nakul Industries health program!")
weeks = yesWeight
days = weeks * 7
months = days / 30
if gender == 1:
mNewCal = mTotalCal - 500
else:
fNewCal = fTotalCal - 500
if mNewCal or fNewCal < 1200:
print("WARNING! your total intake will be less then 1200 calories, please consult a doctor before following this.")
print("In order to lose " + yesWeight + " ,it will take " + weeks + " weeks " + "\n" + "or " + days + " days" + "\n or " + "approximately " + months + " months.")
else:
print(
"In order to lose " + yesWeight + " ,it will take " + weeks + " weeks " + "\n" + "or " + days + " days" + "\n or " + "approximately " + months + " months.")
【问题讨论】:
标签: python error-handling nameerror