Page 301 - AI Ver 1.0 Class 9
P. 301

Program 2:  To input day of the week and in case it is SUNDAY then extra cookie as a reward point to be
              given with the order.



            Algorithm                                              Flowchart
            Start

            Input weekday                                                              START

            if  weekday is same as "SUNDAY" then
                Display " Reward point - Chocolate Cookie FREE !"
                                                                                    Input Weekday
            Stop




                                                                                         Is
                                                                                      Weekday             No
                                                                                      SUNDAY
            Source Code:

            weekday=input("Enter day of the week :")
                                                                                            Yes
            if weekday=="SUNDAY":
                print("Reward Point – Chocolate Cookie FREE !")                 Display "Reward Point –
                                                                                Chocolate Cookie FREE !"

            Output:

            Enter day of the week : SUNDAY                                              STOP
            Reward Point – Chocolate Cookie FREE !




            The if…else Statement
            When  the  condition  is  True  then  the  statements  indented  just  below  the  if statement will be
            executed  and  if  the  condition  is  False  then  the  statements  indented  just  below  the  else statement
            will be executed. The  else  statement  is  optional  and  if  required  can  be  only  one  else statement in one
            if block. The syntax to use the if…else statement is:

            if (condition):
                 Statements for True

            else:
                 Statements for False
            Where,
               • if and else are keywords.

               • condition can be any relation or logical expression.
               • statements are always indented and can be single or a block.







                                                                                Introduction to Python  299
   296   297   298   299   300   301   302   303   304   305   306