新人求助~~ python输出 怎么把浮点数打印成百分比%的符号

新人求助~~ python输出 怎么把浮点数打印成百分比%的符号
我想输出的格式是
It tends to positive
On the positive data is right x% at the time.
positive ratio: 0.xxxx negative ratio: 0.yyyy

下面是代码 print("On the positive data is right '%.2f%%' at the time.") % (sample.pos_ratio*100) 这一行报错了

想问应该怎么改 > <

if __name__ == '__main__':
config = CommandLine()
sample = CaculateClassification(config)
if(sample.pos_ratio > 0.5):
print ("It tends to positive")
print("On the positive data is right '%.2f%%' at the time.") % (sample.pos_ratio*100)
else:
print ("It tends to negative")
print("On the negative data is right '%.2f%%' at the time.") % ((1 - sample.pos_ratio)*100)
print("positive ratio:%f : negative ratio:%f" % (sample.pos_ratio,1 - sample.pos_ratio))
%紧辩槐跟着你要format的string。
print("携颂友On the positive data is right '%.2f%%' at the time."樱搏%(sample.pos_ratio*100))
← 上一篇: 下一篇: →