Python TypeError when dividing a raw input variable by a number

前端 未结 3 691
北恋
北恋 2021-01-20 12:12

I want to convert an entered lb weight to kg and I get the following error...

TypeError: unsupported operand type(s) for /: \'unicode\' and \'float\'<

3条回答
  •  佛祖请我去吃肉
    2021-01-20 12:52

    raw_input returns a string, you should convert the input to float using float():

    float(raw_input("Current Weight (lb): "))
    

提交回复
热议问题