Analysis of examination results. : while « Statement « Python Tutorial






passes = 0                  # number of passes
failures = 0                # number of failures
studentCounter = 1          # student counter

while studentCounter <= 10:
   result = raw_input( "Enter result (1=pass,2=fail): " )
   result = int( result )   # one exam result

   if result == 1:
      passes = passes + 1
   else:
      failures = failures + 1

   studentCounter = studentCounter + 1

print "Passed", passes
print "Failed", failures

if passes > 8:
   print "Raise tuition"








3.4.while
3.4.1.while Loops
3.4.2.The while Statement
3.4.3.use a loop to ensure that the user enters a name
3.4.4.While loop with counter
3.4.5.Counting Loops
3.4.6.break Statement
3.4.7.continue Statement
3.4.8.else Statement ... Take Two
3.4.9.Class average program with sentinel-controlled repetiton.
3.4.10.Analysis of examination results.
3.4.11.Counter-controlled repetition.
3.4.12.while and else