需要浮动?? Python 中的 round() 错误

float required?? Error with round() in Python

无法通过搜索找到此问题的答案。我正在尝试学习一些 Python 并需要您的帮助来完成此功能:

def roundtest():
    i = round(raw_input("call a number: "), 2)
    print i

我的输入和我得到的错误:

call a number: 1.2222

TypeError: a float is required

感谢您的帮助

raw_input returns 一个字符串,然后您必须将其解析为 float,如下所示:

def roundtest():
    i = round(float(raw_input("call a number: ")), 2)
    print i