Python Forum
Help creating a variable as a result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help creating a variable as a result
#1
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')
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
im really gratefull thanks u ! it works how i want
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Creating a variable as a function DPaul 23 6,508 Sep-07-2020, 05:20 PM
Last Post: DPaul
  Creating a variable as a function JarredAwesome 4 2,783 Sep-06-2020, 05:08 AM
Last Post: buran
  creating a variable in a method and using in another method ridgerunnersjw 5 2,932 Oct-04-2019, 04:03 PM
Last Post: buran
  Guidance in Creating random output for a variable. Livne_ye 1 2,482 May-04-2019, 01:18 PM
Last Post: Yoriz
  Creating a variable in for loop dan789 9 4,101 Dec-19-2018, 06:23 PM
Last Post: nilamo
  Multiple "return" statements or "result" variable? WolfWayfarer 7 7,674 Jul-25-2018, 07:51 AM
Last Post: perfringo
  Creating Dynamic Variable Names Dragonexpert 3 8,073 Oct-22-2016, 02:17 PM
Last Post: Dragonexpert

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020