[Python] TypeError: unsupported operand type(s) for /: 'str' and 'float'

[Python] TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’

输入:
rmb_str_value = input(‘请输入人民币(CNY)金额:’)

rmb_value = eval(rmb_str_value)

usd_vs_rmb = 6.77

usd_value = rmb_str_value / usd_vs_rmb

print(‘美元(USD)金额是:’, usd_value)

运行:
TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’

解决:

rmb_str_value为字符类型,替代为 rmb_value为数字,done.

你可能感兴趣的:(python,python)