Whats happening when i run this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Whats happening when i run this?

Why is it showing <function bmi_calculator at something>? https://code.sololearn.com/cB9rvO6xph23/?ref=app

19th Apr 2019, 4:02 AM
Zinnur Hossain
Zinnur Hossain - avatar
4 Answers
+ 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)
19th Apr 2019, 4:48 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
It’s because you’re only referencing the function, not calling it. Try: print(bmi_calculator(height1, weight1))
19th Apr 2019, 4:59 AM
Rowsej
Rowsej - avatar
+ 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)
19th Apr 2019, 4:45 AM
Anna
Anna - avatar
+ 1
Many thanks to everyone who answered, im still just a beginner in programming so im still finding way around it ^_^
19th Apr 2019, 6:16 AM
Zinnur Hossain
Zinnur Hossain - avatar