简体   繁体   中英

NameError in python trying to create a BMI calculator

def bmi_calculator(name,height_m,weight_kg):

        bmi = weight_kg / (height_m ** 2)

print('Your bmi is: ', bmi)
  
bmi_calculator(yerson,1.8,65)

I placed the print statement in the definition and made the name arguement into a string.

def bmi_calculator(name,height_m,weight_kg):

    bmi = weight_kg / (height_m ** 2)
    print('Your bmi is: ', bmi)


name = input("What is your name: ")
height = float(input("What is your height: "))
weight = float(input("What is your weight: "))

bmi_calculator(name,height,weight)

edit: added user input

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM