如果/ Elses语句没有正确执行

时间:2015-06-10 01:00:05

标签: python-3.x if-statement

我已经多次更改了if / else语句,并且 if语句将被执行,即使它不是真的或仅 即使它不成立,也会执行else语句。

def interview():
""" NoneType -> NoneType
Interview the user. """
name = input("What is your name?")
unit = input("What is you preferred choice of unit - standard or imperial?")
weight = float(input("What is your weight?"))
height = float(input("What is your height?"))
a = float(bmi_std(weight, height))
b = float(bmi_std_prime(weight, height))
c = float(bmi_imp(weight, height))
d = float(bmi_imp_prime(weight, height))
e = str(category(weight, height, 's'))
f = str(category(weight, height, 'i'))

print("So," + name + ", your preferred unit is" + unit + ".")
print("Your weight", weight)
print("Your height", height)
if str(unit == 'imperial'):
    print("BMI = " + str(c) + " and your BMI prime = " + str(d))
    print("Category = " + f)
else:
    print("BMI = " + str(a) + " and your BMI prime = " + str(b))
    print("Category = " + e)

这只是我代码的一部分。它的编写方式有问题,因为它看起来很好。我只是编程的介绍。

1 个答案:

答案 0 :(得分:2)

我可以立即看到问题

if str(unit == 'imperial'):应为if str(unit) == 'imperial':