我猜你在学Python。其他的答案是对的。但我要回答你的主要问题:“如何用python计算百分比”

虽然它的工作方式是你做的,但它看起来不是很Python。另外,如果你需要添加一个新的主题,会发生什么?你将不得不添加另一个变量,使用另一个输入,等等。我想你想要所有分数的平均值,所以你也必须修改科目的计数,每次你添加一个新的!看起来一团糟。。。

我将抛出一段代码,其中您唯一需要做的是在列表中添加新主题的名称。如果您试图理解这段简单的代码,那么您的Python编码技巧将遇到一些困难。

#!/usr/local/bin/python2.7
marks = {} #a dictionary, it's a list of (key : value) pairs (eg. "Maths" : 34)
subjects = ["Tamil","English","Maths","Science","Social"] # this is a list
#here we populate the dictionary with the marks for every subject
for subject in subjects:
marks[subject] = input("Enter the " + subject + " marks: ")
#and finally the calculation of the total and the average
total = sum(marks.itervalues())
average = float(total) / len(marks)
print ("The total is " + str(total) + " and the average is " + str(average))

Here您可以测试代码并进行测试。