Page 111 - TP_Play_V2.1_class8
P. 111

user_type = "member"

                 coupon_value = "invalid"

                 IF user_type = "member" OR coupon_value = "valid" THEN

                     PRINT "Eligible for discount"

                 ELSE

                     PRINT "Not eligible for discount"

                    Eligible for discount



                 WHAT DID YOU NOTICE?

                 Both the programs have two IF conditions joined together using AND or OR. The final result
                 depends on the combined result.
                    AND: Results in true only if both the conditions are true. If any one condition is false, the result
                    will be false.

                    OR: Results in true if at least one of the conditions is true. If both are false, the result will be
                    false.
                 Now, write your answers for both.

                 1.   age =20                                       2.   shop = 500
                     IF age >= 12 AND age <= 19 THEN                    customer = "new"

                         PRINT "You are a teenager"                     IF shop > 100 OR customer = "old" THEN
                     ELSE                                                   PRINT "Eligible for a free gift"
                         PRINT "You are not a teenager"                 ELSE
                                                                            PRINT "Not eligible for a free gift







                     LOOPS IN A PROGRAM


                 A loop allows a set of instructions or a block of code to be executed repeatedly. It helps in
                 automating repetitive tasks and makes the code more efficient by avoiding the need to write the
                 same instructions multiple times. When a loop repeats forever (endlessly), it is called an infinite
                 loop. There are two types of loops.
                    Counting loops: These repeat a block of code a specific number of times.

                     Conditional loops: These repeat until a certain condition is reached, which means they keep
                    going until the condition remains true.






                                                                                     Algorithmic Intelligence    109
   106   107   108   109   110   111   112   113   114   115   116