Page 404 - Computer_Science_F5
P. 404

Instructions:
               Use the following codes to visualise its execution in Thonny software:

                for i in range(1, 14):
                   if i % 2 == 0:                                                                  Chapter Six: Object oriented programming with Python
          FOR ONLINE READING ONLY
                       continue
                   print(i)

               Step 1:   Open Thonny software

               Step 2:   Open the file you saved in any location using Thonny interface. The file
                        will be shown as in Figure 6.3.














                               Figure 6.6: Visualising step by step execution of program


                      Example 6.1:


                Placeholder function
                     # Placeholder for a function that does nothing

                     def placeholder_function():

                         pass  # No implementation yet

              In this example, you have a function called “placeholder_function()” that is defined
              but does not have any implementation  yet.  The “pass” statement  is used as a
              placeholder to indicate that there is no code inside the function body at the moment.


                       Example 6.2:

               Class definition without members
                   # Using pass in a class definition
                   class MyClass:
                       pass  # Class definition without any members yet


                                                    395
               Student’s Book  Form Five



     Computer Science Form 5.indd   395                                                     23/07/2024   12:34
   399   400   401   402   403   404   405   406   407   408   409