For Repetition Structure

The for repetition structure handles all the details of counter-controlled repetition. To illustrate the power of for, let us rewrite the program of Fig. 3.17. Figure 3.18 shows the result. The program operates as follows. When the for structure begins executing, function range creates a sequence of values in the range 0-9 (Fig. 3.19). The first value in this sequence is assigned to variable counter, and the body of the for structure (line 6) executes. For each subsequent value in the sequence,...

Using Xhtml Forms to Send Input and Using Module cgi to Retrieve Form Data

If Web page users had to type all the information that the page required into the page's URL every time the user wanted to access the page, Web surfing would be quite a laborious task. XHTML provides forms on Web pages that provide a more intuitive way for users to input information to CGI scripts. The < form> and < form> tags surround an XHTML form. The < form> tag typically takes two attributes. The first attribute is action, which specifies the operation to perform when the user...

Formulating Algorithms with Top Down Stepwise Refinement Case Study Nested Control Structures

Let us work another complete problem. We once again formulate the algorithm using pseudocode and top-down, stepwise refinement and we develop a corresponding Python program. Consider the following problem statement A college offers a course that prepares students for the state licensing exam for real estate brokers. Last year, several of the students who completed this course took the licensing examination. Naturally, the college wants to know how well its students did on the exam. You have...

Common Programming Error

Failure to indent all statements that belong to an if suite or an else suite results in a syntax error. The flowchart of Fig. 3.4 illustrates the flow of control in the if else structure. Once again, note that besides small circles and arrows the symbols in the flowchart are rectangles for actions and diamonds for decisions . We continue to emphasize this action decision model of computing. Imagine again a bin containing empty double-selection structures. The programmer's job is to assemble...

If Selection Structure

Selection Structure Flow Chart

Selection structures choose among alternative courses of action. For example, suppose that the passing grade on an examination is 60. Then the pseudocode statement If student's grade is greater than or equal to 60 PrintPassed determines whether the condition student's grade is greater than or equal to 60 is true or false. If the condition is true, then Passed is printed, and the next pseudocode statement in order is performed. Remember that pseudocode is not a real programming language. If the...

Structured Programming Summary

Structures Flowchart

Just as architects design buildings by employing the collective wisdom of their profession, so should programmers design their programs. The field of computer programming is younger than architecture, and our collective wisdom is considerably sparser. We have learned that structured programming produces programs that are easier than unstructured programs to understand and hence are easier to test, debug, modify, and even prove correct in a mathematical sense. Figure 3.32 summarizes Python's...

While Repetition Structure

A repetition structure allows the programmer to specify that a program should repeat an action while some condition remains true. The pseudocode statement While there are more items on my shopping list Purchase next item and cross it off my list 26, Nov 16 2001, 11 44 11 MSC 32 bit Intel on copyright, credits or license for more informa- describes the repetition that occurs during a shopping trip. The condition, there are more items on my shopping list is either true or false. If it is true,...

Formulating Algorithms with Top Down Stepwise Refinement Case Study Sentinel Controlled Repetition

Let us generalize the class-average problem. Consider the following problem Develop a class-averaging program that processes an arbitrary number of grades each time the program is executed. In the first class-average example, the program knows the number of grades 10 to be entered by the user. In this example, no indication is given of how many grades will be entered. The program processes an arbitrary number of grades. How can the program determine when to stop the input of grades How will it...