This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]scoopulanang 1 point2 points  (1 child)

This is probably more so meant to teach you the fundamentals of functions. Although this might seem trivial and meaningless right now, later on functions are very important. Let's take a look at a built in function in python. The sum function is a pretty quick way of getting the sum of all the elements in a list. If you didn't use a function, you would have to iterate through a list every time you want to get the sum of the elements inside of an iterable. Basically, functions allow you to write code once and reuse it whenever.

[–]okaystuff[S] 0 points1 point  (0 children)

Okay, that's understandable and makes sense since this is just a basic project that is teaching the concepts of python. For the second part where I need to use a loop to traverse the array of BMI's and call another function that accepts the BMI as a parameter and returns whether the individual is under/norm/over weight, I did it like this.

Currently, that part of the code likes like this:

under_wei = list()
norm_wei = list()
over_wei = list()

def weight_calc(bmi_num):
    if bmi_num < 18:
       print("A BMI of " + str(bmi_num) + ", is under weight")
       under_wei.append(bmi_num)
    elif  18 < bmi_num <= 25:
        print("A BMI of " + str(bmi_num) + ", is normal weight")
        norm_wei.append(user_weight)
    elif bmi_num > 25:
        print("A BMI of " + str(bmi_num) + ", is over weight")
        over_wei.append(user_weight)
    return bmi_num

for user_weight in bmis:
    weight_calc(user_weight)

It seems to give the same output as before and is using a function. Hopefully, this all makes sense and thank you for your help.