Class average program with sentinel-controlled repetiton. : While : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » While »

 

Class average program with sentinel-controlled repetiton.


total = 0          # sum of grades
gradeCounter = 0   # number of grades entered

grade = raw_input"Enter grade, -1 to end: " )   # get one grade
grade = intgrade )   # convert string to an integer

while grade != -1:
   total = total + grade
   gradeCounter = gradeCounter + 1
   grade = raw_input"Enter grade, -1 to end: " )
   grade = intgrade )

if gradeCounter != 0:
   average = floattotal / gradeCounter
   print "Class average is", average
else:
   print "No grades were entered"



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» While