[Solved] Absolute beginner looking for solution


This is very simple, and is pretty much related to your understanding of the BMI’s formula. The code that suits your requirements would be the following:

maxweight = (height**2/10000)*24.9
dif = round(abs(maxweight-weight),2)
print(name+", you have",dif,"kilograms to go until you reach the maximum normal weight")

This works for both underweight and overweight values, always returning a positive value using the function abs().

Alternatively, you can use a function, which handles both cases better:

def getDifferenceString(name,weight,height):
 maxweight = (height ** 2 / 10000) * 24.9
 if maxweight<weight:
  return "You should go to the gym, "+name+", because you are "+str(round(abs(maxweight-weight),2))+" over the maximum normal weight"
 else:
  return "No worry, "+name+", you can put on " + str(round(abs(maxweight - weight), 2)) + " more kilos"

print(getDifferenceString(name,weight,height))

Explanation:

  • maxweight represents the maximum normal weight directly out of BMI formula
  • dif is the absolute value of the difference between the weight of the person and maxweight, rounded at 2 decimal places

Hope this helps!

2

solved Absolute beginner looking for solution