Python: raw_input and unsupported operand type(s)

前端 未结 3 571
抹茶落季
抹茶落季 2020-12-12 05:45

I am a newbie to Python and have been recently attempting to create a BMI calculator, but I am having errors with the following code:

def calculator():

             


        
3条回答
  •  执笔经年
    2020-12-12 05:58

    raw_input always returns a str object. You need to explicitly convert the input to an int. You can either do

    val = int(raw_input(...))
    

    or

    val = raw_input(...)
    val = int(val) 
    

    As others have mentioned, there are many errors in your code. Here is one:

    if height == exit:
    

    Same problem with weight condition. I am just going to point out as you didn't ask about this in question so I will let you find out what the problem is :).

提交回复
热议问题