+ 3
Whats happening when i run this?
Why is it showing <function bmi_calculator at something>? https://code.sololearn.com/cB9rvO6xph23/?ref=app
4 Réponses
+ 7
bmi_calculator is a function. On line 6, you are merely defining the function, not calling it or putting it in action. Nothing is executed. You should call it with parameters.
Since your function does not return anything, don't place the function call in a print statement.
Remember to convert height1 and weight1 to numeric data types instead of the default string returned by input().
print("This is a BMI calculater!")
print("Please enter your height in metres and your weight in kilogrammes")
height1 = float(input("Height: "))
weight1 = float(input("\nWeight: "))
def bmi_calculater(height, weight):
bmi = weight/height**2
if bmi > 25:
print("You are overweight")
else:
print("you are not overweight")
bmi_calculater(height1, weight1)
+ 6
It’s because you’re only referencing the function, not calling it. Try:
print(bmi_calculator(height1, weight1))
+ 4
Because with print(bmi_calculater) you print the name of the function. To call the function, use bmi_calculater(height1, weight1). Don't forget to turn the input into floats though, otherwise you'll be calculating with strings (which won't work)
+ 1
Many thanks to everyone who answered, im still just a beginner in programming so im still finding way around it ^_^