Code

Making stuff do stuff

Code

Code Introtext

(Filler text)

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.

Jump to sections:

BMI-Calculator in Python

This is a small test

This is a piece of code for practicing purposes. One of the things with learning to code for me is to make sure there aren't any dead ends in my user stories.


  ##BMI-Calculator

  ##FIELD NOTES:
  #Metric BMI Formula = weight (kg) / height2 (m2)
  #BMI Categories:
  #Underweight = <18.5
  #Normal weight = 18.5–24.9
  #Overweight = 25–29.9
  #Obesity = BMI of 30 or greater

  ##Defintion Functions:

  #Input

  def query():

      input_height_legit=False
      while input_height_legit==False:
          try:
              height=int(input("How tall are you in centimeter? "))
          except ValueError:
              print("Not an integer! Try again.")
              continue
          else:
              if 57 <= int(height) <= 272: #Error Message for unreasonable numbers

                  input_height_legit=True
              else:
                  input_height_legit=False
                  print("That doesn't seem reasonable! Try that again!")
      print("According to your input your are",height,"centimeters tall")

      input_weight_legit=False
      while input_weight_legit==False:
          try:
              weight=input("How much does your body weight in kilograms? ")
          except ValueError:
              print("Not an integer! Try again.")
              continue
          else:
              if 2 <= int(weight) <= 635: #Error Message for unreasonable numbers
                  input_weight_legit=True
              else:
                  input_weight_legit=False
                  print("That doesn't seem reasonable! Try that again!")
      print("According to your input your are",weight,"kilogramms heavy")

      return float(height), float(weight)


  #Processing

  def processing_bmi():

      bmi=weight/(height**2)*10000

      return round(bmi, 1)


  def assigning_category():

      category=""
      if bmi < 18.5:
          category="underweight"
      elif 18.5 <= bmi <= 24.9:
          category="normal weighted"
      elif 25 <= bmi <= 29.9:
          category="overweight"
      elif bmi >= 30:
          category="obese"

      return str(category)


  #output

  def output(bmi, category):

      print("Your Body Mass Index therefore is:",bmi)
      print("This makes you",category)


  ##MAIN PROGRAM

  height, weight=query() #promts! (visible)
  bmi=processing_bmi() #backend-magic (invisible)
  category=assigning_category() #promts (visible)
  output(bmi, category)