Page 361 - Ai_417_V3.0_C9_Flipbook
P. 361

3.  Developing the solution: Design a detailed algorithm and choose appropriate tools and technologies. It is
                   always recommended to first write an algorithm and draw a flowchart for solving a problem and then only
                   write the program. This translates analysis into a practical, actionable plan.
                 4.  Coding and implementation: This is the last step where every instruction of an algorithm is converted into
                   a computer understandable instruction by using the syntax and semantic of a specific computer language.


                         Control Structures

                 Control structures are a set of instructions that control the flow of instructions in a program. It is a programming
                 tool that determines the order of execution of the statements in any programming language. There are three
                 different types of control structures: sequential flow, selection flow, and repetition flow.
                 Let us learn about these in detail.

                 Sequential Flow

                 In sequential flow, the statements are placed one after the other and the flow of execution occurs starting from line
                 1, line 2 and so on with a top-down approach. It is the default flow followed in any programming language. For
                 example, the steps for calculating the percentage of any student by taking as an input marks of English, Science,
                 Maths are as follows:
                 Step 1   Start

                 Step 2   Input Eng, Science, Math
                 Step 3   Total = Eng+Science+Math
                 Step 4   Percentage = (Total / Maximum_Marks) * 100
                 Step 5   Display Percentage
                 Step 6   Stop


                 Selection Flow
                 Selection flow is also known as branching control as the flow of control branches based on a condition. A
                 condition evaluates to either TRUE or FALSE. In the case of TRUE, the flow of control follows the set of instructions
                 written for True. In case it is FALSE, then it follows the other route. For example, consider the scenario where an
                 award is given only if the percentage is more than 90:
                 Step 1   Start
                 Step 2   Input Eng,Science, Math
                 Step 3   Total= Eng+Science+Math
                 Step 4   Percentage = (Total / Maximum_Marks) * 100

                 Step 5   Display Percentage
                 Step 6   If Percentage> 90 then
                              Display "Award given"
                 Step 7   else

                              Display "No award"
                 Step 8   Stop

                 Repetition Flow

                 Repetition flow, also known as a loop, repeats a set of instructions a number of times based on a condition. For
                 example, if we wish to repeat the above steps of calculating percentage for 10 students then we use the concept
                 of repetition.
                                                                                        Introduction to Python  359
   356   357   358   359   360   361   362   363   364   365   366