Page 300 - AI Ver 1.0 Class 9
P. 300

The if Statement
        We use the if statement to do conditional programming. Condition with the if statement can also be written
        within the parenthesis ( ). However, it is optional to use parenthesis. It is must to specify colon (:) after writing a
        condition with the if statement. The number of statements (also called as a Block) written within if statement
        can be of any size. A statement or block of statement will be executed only when the condition is True. If the
        condition is False then nothing happens.
        Syntax of the if statement:

        if (condition):

                 statements
        Where,

           • if is a keyword.
           • condition can be any relational or logical expression.

           • statements are always indented can be single or a block.
          Program 1:  To input the percentage of a student and award "Certificate of Excellence" if the student gets more
          than 80%.

        Algorithm                                                       Flowchart

        Start                                                                           START
        Input Percent

        if Percent is more than 80 then                                              Input Percent
            Display "Congratulations"

            Display "Your are awarded Certificate of Excellence"

        Stop                                                                              Is            No
                                                                                     Percent > 80?
        Source Code:

        percent=int(input("Enter your percentage :")                                        Yes

        if percent>80:                                                          Display "Congratulations"
                                                                                Display "Yes are awarded..."
            print("CONGRATULATIONS")
            print("You are awarded– 'Certificate of Excellence'")
                                                                                         STOP

        Output:
        Enter your percentage :89

        CONGRATULATIONS
        You are awarded– 'Certificate of Excellence'











                  298   Touchpad Artificial Intelligence-IX
   295   296   297   298   299   300   301   302   303   304   305