classAverage.py源代码分析

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

# initialization phase

total = 0 # sum of grades

gradeCounter = 0 # number of grades entered

# processing phase

grade = raw_input( "Enter grade, -1 to end: " ) # get one grade

grade = int( grade ) # convert string to an integer

while grade != -1:

total = total + grade

%获取分数的总和

gradeCounter = gradeCounter + 1

%分数的个数

grade = raw_input( "Enter grade, -1 to end: " )

%获取分数的输入

grade = int( grade )

%将string型转化为int型

# termination phase

if gradeCounter != 0:

average = float( total ) / gradeCounter

%获取平均值

print "Class average is", average

%打印平均值

else:

print "No grades were entered"

%否则提示错误

你可能感兴趣的:(C++,c,C#)