Help creating a variable as a result - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help creating a variable as a result (/thread-27710.html) |
Help creating a variable as a result - Realen - Jun-18-2020 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') RE: Help creating a variable as a result - buran - Jun-18-2020 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.
RE: Help creating a variable as a result - Realen - Jun-18-2020 im really gratefull thanks u ! it works how i want |