Python Forum

Full Version: Help creating a variable as a result
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello ~
I am new to programming I started 2 weeks ago, I was so curious and passionate about this, well, I am trying to code a program that can give me a variable as a result using a BMI calculator I created, but I am having trouble trying to generate the result based on the variable "bmi" i dont know if im using the right datatype (thanks)

weight = int(input('Put weight'))
Height = float(input('Put Height'))
bmi = float(weight / (Height ** 2))
under_weight = list(range(14, 19))
normal_weight = list(range(19, 26))
over_weight = list(range(26, 31))
print('Your BMI is', bmi, 'greetings uwu')
print()
if bmi == under_weight:
    print('under_weight')
elif bmi == normal_weight:
    print('normal Weight')
elif bmi == over_weight:
    print('over weight')
bmi is float, and you compare it with a lists - under_weight, normal_weight, over_weight. They will never be equal.
In this case you don't need lists, they will not do what you want anyway.
one way to do what you try is like this:
if 14 <= bmi < 19:
by the way, bmi = weight / Height ** 2 is enough, no need to explicitly cast to float. Also it's good to be consistent with respect to variable names - use height, not Height. These are also PEP* recommendations.
im really gratefull thanks u ! it works how i want