fork(1) download
  1. from sys import exit
  2.  
  3. bmi = ["what is bmi?", "what is bmi", "bmi", "bmi?"]
  4.  
  5. male=["male","m"]
  6.  
  7. female=["female", "f"]
  8.  
  9. def bmi_q():
  10. print "Very good! Let's start with your age."
  11. age= float(raw_input("How old are you %s? > " %name))
  12.  
  13. height= float(raw_input("How tall are you, in m? > "))
  14.  
  15. weight=float(raw_input("What do you weigh in kg? > "))
  16. Gender=raw_input("Finally, are you male or female? (No offense.) > ")
  17.  
  18. result = bmi_c(weight,height)
  19.  
  20. analysis(result)
  21.  
  22. def analysis(result):
  23. if result < 18.5:
  24. print "Your BMI is %d." % round(result,2), "You are far too skinny, please eat more."
  25. print "A healthy BMI is between 18.5 and 25."
  26. exit(0)
  27.  
  28. elif result > 25:
  29. print "Your BMI is %d." % round(result,2), "You are far too fat, please eat less."
  30. print "A healthy BMI is between 18.5 and 25."
  31. exit(0)
  32.  
  33. else:
  34. print "Your BMI is %d." % round(result,2), "Congratulations! You're well fit."
  35. print "A healthy BMI is between 18.5 and 25."
  36. exit(0)
  37.  
  38. def bmi_c(weight,height):
  39. return weight / (height**2)
  40.  
  41. def consent_q():
  42. unsure = True
  43.  
  44. while True:
  45. print "Would you like to calculate your BMI?"
  46. consent = raw_input("> Answer: \"Yes\", \"No\", or \"What is BMI?\" > ")
  47.  
  48. if consent.lower() == "no":
  49. print ("What did you open a script called \"BMI\" for then??? This is all I can do!")
  50.  
  51. elif consent.lower() in bmi:
  52. print """Wise man at CDC say:
  53. \"Body Mass Index (BMI) is a person's weight in kilograms
  54. divided by the square of height in meters.
  55.  
  56. A high BMI can be an indicator of high body fatness.
  57.  
  58. BMI can be used to screen for weight categories that may
  59. lead to health problems but it is not diagnostic of the
  60. body fatness or health of an individual.\" """
  61.  
  62. elif consent.lower() == "yes":
  63. unsure = False
  64. bmi_q()
  65.  
  66. else:
  67. print "Sorry, me no hablo ingles so good. Try again."
  68.  
  69.  
  70. print "Thank you for running the BMI script."
  71. print "Before we begin, please tell me your name:"
  72. name=raw_input("> ")
  73. print "Hello %s, nice to meet you." % (name)
  74. consent_q()
Success #stdin #stdout 0.01s 9016KB
stdin
Me
Yes
1
1
1
m
stdout
Thank you for running the BMI script.
Before we begin, please tell me your name:
>   Hello Me, nice to meet you.
Would you like to calculate your BMI?
> Answer: "Yes", "No", or "What is BMI?" >   Very good! Let's start with your age.
How old are you Me?   >   How tall are you, in m?    >   What do you weigh in kg?    >   Finally, are you male or female? (No offense.)    >   Your BMI is 1. You are far too skinny, please eat more.
A healthy BMI is between 18.5 and 25.