Page 404 - Ai_417_V3.0_C9_Flipbook
P. 404

for var in range(1,10,2):                                             1,3,5,7,9
                         print(var,end=",")

                     for count in range(1,10):                                             1,2,3,4,5,6,7,8,9
                         print(count,end=",")
                     for var in range(10):                                                 0,1,2,3,4,5,6,7,8,9

                         print(var,end=",")
                     for var in range(5,0,–1):                                             5,4,3,2,1
                         print(var,end=",")
                     for var in range(5,5):                                                No output

                         print(var,end=",")
                     for var in range(5,3):                                                No output
                         print(var,end=",")
                     #Program to generate alternate numbers for the given range enter starting value: 5

                     starts=int(input("enter starting value: "))                           enter ending value: 10
                     ends=int(input("enter ending value: "))                               5,7,9,
                     for var in range(starts, ends+1,2):
                         print(var,end=",")



                            Brainy Fact


                    Comparison  operators  (<,  >,  <=,  >=,  !=,  ==)  and  logical  operators  (and,  or)  returns  True  or
                    False.





              The while Loop
              The while loop is used to repeat a set of instructions as long as the condition is true. It means when the number
              of iterations are not fixed/indefinite before we start with the execution of a loop. Therefore, it is known as an
              indefinite loop. Indentation of statements is must to specify the block of statements to be repeated using while
              loop.
              This loop is also called an entry-controlled loop as it checks for the condition in the beginning. If the condition
              is 'True' then the body of the loop will be executed. If the condition is 'False' then it will not be allowed to enter
              within the loop and it stops. The syntax of the while loop is:

                while <condition>
                    Statements
              Where,

                 • while is a keyword.
                 • condition is a criterion to repeat the instructions. The instructions repeat until the condition is 'True'. As soon
                 as the condition is 'False', the control exits from the loop.
                 • Statements are always indented can be single or a block and are repeated till the condition is True.



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