需要浮动??Python 中的 round() 错误 [英] float required?? Error with round() in Python
本文介绍了需要浮动??Python 中的 round() 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法通过搜索找到此问题的答案.我正在尝试学习一些 Python 并且需要你的帮助来实现这个功能:
could not find this question answered by search. I am trying to learn some Python and need your help this this function:
def roundtest():
i = round(raw_input("call a number: "), 2)
print i
我的输入 &我得到的错误:
My input & the error I get:
call a number: 1.2222
TypeError: a float is required
感谢您的帮助
推荐答案
raw_input
返回一个字符串,然后您必须将其解析为 float
,如下所示:
raw_input
returns a string, which you then have to parse in to a float
, like so:
def roundtest():
i = round(float(raw_input("call a number: ")), 2)
print i
这篇关于需要浮动??Python 中的 round() 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文