Python TypeError when dividing a raw input variable by a number

前端 未结 3 692
北恋
北恋 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:48

    That's because with raw_input, the input is raw, meaning a string:

    lbweight = float(raw_input("Current Weight (lb): ") )
    
    kgweight = lbweight/2.20462
    

提交回复
热议问题