Page 310 - Artificial Intellegence_v2.0_Class_9
P. 310

If a = 5 and b = 0, then it will display:
           ZeroDivisionError: division by zero


                 Control Statements

        As you know that a program is a set of instructions given to a computer to do a specific task. The order of
        execution of these instructions controls the flow of a program. There are three important ways to control the
        flow of a program which are interpreted by any programming language in a structured manner. These are:
           • Sequential
           • Selection
           • Iterative
        Let us learn about these in detail.

                 Sequential Statements


        A step-by-step process of execution of code is called sequential flow of control. This is the default flow of
        execution of a program. It means that the computer will run the code one line at a time starting from line 1,
        followed by line 2 and so on till it reaches the last line of the program.
        Let us take an example of making a mango smoothie. The steps will be:
        1.  Put mango pieces in a Mixer jar
        2.  Add sugar
        3.  Add milk
        4.  Churn the mixer jar
        5.  Pour in a glass
        Let us do some more examples:
           • Input First name and Last name from the user and display full name.

           Algorithm                                                       Flowchart
             Start
             Input FirstName                                                                START
             Input LastName
             FullName= FirstName + LastName                                                INPUT
             Display FullName                                                       First Name, Last Name
             Stop

        Source Code:                                                            FullName=First Name+Last Name

        FirstName=input("Enter your First Name :")
        LastName=input("Enter your Last Name :")
                                                                                           Display
        FullName=FirstName+" "+LastName                                                   Full Name
        print("Hello !" +FullName+" Welcome to the World of Python")
        Output:
        Enter your First Name :Suzan                                                        STOP
        Enter your Last Name :Christopher
        Hello !Suzan Christopher Welcome to the World of Python
           • Input Length and Breadth of a Rectangle. Calculate the Area and Perimeter




              308     Touchpad Artificial Intelligence (Ver. 2.0)-IX
   305   306   307   308   309   310   311   312   313   314   315