Class average program with sentinel-controlled repetiton. : while « Statement « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » Statement » while 
3.4.9.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"
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.