Page 402 - Ai_417_V3.0_C9_Flipbook
P. 402

Step 4   if Num is divisible by 5 then                            Flowchart
                            Display "It is multiple of 5"
                                                                                    START
               Step 5   else
                            Display "Not multiple of 5"
                                                                                  Input Num
               Step 6   else
                            Display "Sorry! Invalid Number"

               Step 7   Stop                                                          Is      No       Display
                                                                                   Num > 0?          "Invalid No"
              Source Code:
              Num=int(input("Enter a number: "))
                                                                                       Yes
              if Num>0:
                  if Num%5==0:                                                        Is      No       Display
                                                                                 Num %5==0?
                      print(Num,"is multiple of 5")                                               "Not multiple of 5"
                  else:
                      print(Num,"is not multiple of 5")                                Yes
              else:                                                                Display
                  print("Sorry! Invalid Number")                                "Multiple of 5"
              Output:

              Enter a number: 34                                                     STOP
              34 is not multiple of 5



                            Brainy Fact

                   True means non-zero number or non-empty object and False means None or zero number or empty
                   object or none.





                       Iterative  Statements

              In Python, the process of repeating a set of instructions based on a condition is called loop or iteration. There
              are two types of loops in Python—for loop and while loop. Let us learn about them in detail.

              The for Loop

              The for loop is used to repeat a set of instructions for a fixed number of times. This means the number of
              iterations are known/definite before we start the execution of the loop. Therefore, the for loop is also known
              as definite loop. Indentation of statements is must to specify the block of statements to be repeated using the
              for loop. There are commonly two different ways of using the for loop:
                 • Using Sequence: In this type of for loop, a sequence of values is used over which the loop iterate. The syntax
                 to use the for loop with a sequence is:

                for <counter variable> in <sequence>:
                    Statements
                 Where,
                    ✶ for is a keyword.



                    400     Touchpad Artificial Intelligence (Ver. 3.0)-IX
   397   398   399   400   401   402   403   404   405   406   407