Python新手,但这怎么不产生整数>。<我在值的前面添加了int,希望通过将它们专门设置为int,我不会得到40.0%的回报,我只是想说40%
score = 4
opLimit = 10
total = int(100) * int(score)/int(oqLimit)
print(total,"%")
答案 0 :(得分:1)
如果您使用的是Python3,则应使用字符串格式。
score = 4
opLimit = 10
total = 100 * score/oqLimit
print("{:.0f}%".format(total))
# {...} defines a substitution field
# :... defines the formatting options
# .0f indicates to represent floats with 0 digits after the decimal