While loop with sentinel-controlled repetiton. : While : Language Basics PYTHON examples


PYTHON examples » Language Basics » While »

 

While loop with sentinel-controlled repetiton.


While loop with sentinel-controlled repetiton.
 
total = 0          
gradeCounter = 0   

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 examples

 Navioo Language Basics
» While