Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.4.4限制为2位的isn';t工作(格式(self.NUMBER,';.2f';)_Python_Digits - Fatal编程技术网

Python 3.4.4限制为2位的isn';t工作(格式(self.NUMBER,';.2f';)

Python 3.4.4限制为2位的isn';t工作(格式(self.NUMBER,';.2f';),python,digits,Python,Digits,我正在尝试一个自我修正的答案Smth。 我尝试了round(self.correct\u answer,2)和几种不同的格式(self.correct\u answer,.2f')键入内容 是因为“自我”吗 self.correct_answer = self.numbers1[self.number1] / self.numbers2[self.number2] format(self.correct_answer, '.2f') 格式不合适(就像Python中的任何其他字符串相关函数/方

我正在尝试一个自我修正的答案Smth。 我尝试了
round(self.correct\u answer,2)
和几种不同的
格式(self.correct\u answer,.2f')
键入内容

是因为“自我”吗

self.correct_answer = self.numbers1[self.number1] / self.numbers2[self.number2] 
format(self.correct_answer, '.2f')

格式
不合适(就像Python中的任何其他字符串相关函数/方法一样)。您需要重新分配其返回值:

formatted=格式(self.correct_-answer,.2f')

记住Martijn Pieters在评论中提到的内容
format
返回字符串,而不是浮点。

format()
round()
返回结果。数字是不可变的对象,它们不会被改变
format()
还生成一个字符串对象,而不是另一个数字,用于帮助您表示值,而不是进行舍入。