mardi 9 juin 2015

If/ Elses statement not executing properly

I've altered the if/else statements several times and either only the if statement will be executed even if it's not true or only the else statement will be executed even if it's not true.

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)

This is just part of my code. Is there something wrong in the way its written because it looks fine to me. I'm only an intro to programming.

Aucun commentaire:

Enregistrer un commentaire