Python Forum

Full Version: python **
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
May I ask why Python is calculating the height**2 differently. The height should be 3.2?


def bmi(name, height, mass):
h = (height ** height)
print('Height on p:', h)
print('The mass is: ', mass)
rez = mass / h
print(rez)
if rez < 18.5:
print(name + " is Underweight")
elif rez >= 18.5 and rez < 24.9:
print(name + " has Normal Weight")
elif rez >= 25 and rez <=29.9:
print(name + " is Overweight")
elif rez > 30:
print(name + " is Obese!!!")

ex = bmi('name', 1.8, 94)


OUTPUT:
Height on p: 2.880650097068328
The mass is: 94
32.63152303560398
name is Obese!!!
Nowhere in your code have you asked for height ** 2 (or for height * height, which would be the same thing).

Instead you have coded height ** height, which is a different expression.
That is height raised to the height power.
BTW - when learning a new language I start with a BMI calculator. Welcome!
(Oct-19-2020, 11:12 PM)jefsummers Wrote: [ -> ]That is height raised to the height power.
BTW - when learning a new language I start with a BMI calculator. Welcome!

Thank you for your feedback :)

Here is the final version of my BMI calculator. Any other idea that can be good project?
[Image: ff.png]
Might get some ideas from this site:
Python projects for beginners and beyond