【发布时间】:2014-03-04 10:19:22
【问题描述】:
这是我的程序
print" Welcome to NLC Boys Hr. Sec. School "
a=input("\nEnter the Tamil marks :")
b=input("\nEnter the English marks :")
c=input("\nEnter the Maths marks :")
d=input("\nEnter the Science marks :")
e=input("\nEnter the Social science marks :")
tota=a+b+c+d+e
print"Total is: ", tota
per=float(tota)*(100/500)
print "Percentage is: ",per
结果
Welcome to NLC Boys Hr. Sec. School
Enter the Tamil marks :78
Enter the English marks :98
Enter the Maths marks :56
Enter the Science marks :65
Enter the Social science marks :78 Total is: 375 Percentage is: 0.0
但是,百分比结果是0。如何在 Python 中正确计算百分比?
【问题讨论】:
-
不相关:如果您有分数,则将其打印为百分比:
print "{:.0%}".format(sum(marks) / (len(marks) * perfect_mark * 1.0))
标签: python python-2.7 percentage