Page 134 - ComputerGenius_V2.1_Class8
P. 134

Critical Thinking
                         Quest


                       1.  Write the syntax of the for loop.



                       2.  Write the syntax of the while loop.


                       3.  Write the output of the following:
                           a.  for num in range(-10, 0, 1):
                                       print(num)

                           b. count = 0
                               while (count < 5):
                                    count = count + 1

                                    print("Orange Education")






                         Let's REFRESH


                     l   In Python, the body of the ‘if’ statement is indicated by the indentation. Body starts with an indentation
                       and the first unindented marks the end.
                     l   Python interprets non-zero values as True, while ‘None’ and 0 are interpreted as False.
                     l   The  ‘if..else’  statement  evaluates  the  test  expression  and  will  execute  the  body  only  if the  test
                       condition is True. If the condition is False, the body of ‘else’ is executed.
                     l   The ‘elif’ is short for ‘else if’. It allows us to check for multiple expressions.
                     l   The ‘For’ loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects.

                     l   The while loop in Python is used to iterate over a block of code as long as the test expression (condition)
                       is true.




                                                        Exercise




                  A.  Tick ( ) the correct option.

                      1.  Which of these is not a valid Python loop?

                          (i)  for loop                                    (ii)  if loop
                         (iii)  while loop                                 (iv)  None of these



                      132    Computer Genius (V2.1)-VIII
   129   130   131   132   133   134   135   136   137   138   139