Page 101 - TP_Play_V2.2_Class8
P. 101

Take Off                                                          Century   #Critical Thinking
                                                                                                    21 st
                                                                                                   Skills
                      State whether these statements are true or false.

                      1.  Python does not support conditional statements.

                      2.  We can use if statement inside other if statement.
                      3.  We can check multiple conditions in Python.






                      LOOPING IN PYTHON


                 Sometimes, you need to repeat a task multiple times or you may need to repeat the task either a certain
                 number of times or until a condition is satisfied. In Python, the statements that are used to repeat a
                 set of instructions are called iterative or looping statements. Looping statements are very useful and
                 necessary for developing applications.
                 Python provides two types of looping statements—for and while. The for statement is used to repeat
                 an instruction or a set of instructions a fixed number of times. Whereas, the while statement is used to
                 repeat a set of instructions until a condition evaluates to true. Let’s discuss these statements in brief.

                      THE FOR STATEMENT


                 The for statement executes a simple or compound statement for a fixed number of times. The syntax
                 of the for statement is given below:
                                                                              for each
                 for <variable> in <iterator>:
                                                                               item in
                        Statements                                            sequence

                                                                       Last item    True
                                                                       reached?

                                                                             False

                                                                       Execute the
                                                                        for block


                                                                               Exit loop
                 Program 1: To print all the days of a week
                     Program1.py

                  File  Edit  Format   Run   Options   Window    Help

                  #Program to print all days of the week

                  days = ('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
                  for x in days:
                      print(x)




                                                                                                   #Loops in Python  99
   96   97   98   99   100   101   102   103   104   105   106