Page 296 - CTS - CSA TP - Volume 2
P. 296

COMPUTER SOFTWARE APPLICATION - CITS




           Output:










           TASK 8 : Write a program that uses the locals function to display all local variables in the program
           Code:
           # 8. locals

           local_variables = locals()
           print(f”Local variables: {local_variables}”)
           Explanation:
           1  The locals() function returns a dictionary containing the current local symbol table. In this example, locals()
              is called without any arguments, and it returns a dictionary containing  all the local variables  and their
              corresponding values within the current scope.
           2  This can be particularly useful for debugging or inspecting the local variables within a function or code block.
              However, it’s important to note that the result may vary depending on where locals() is called within the code.
           Output:















           TASK 9: Write a program that finds and prints the maximum value from a given list of numbers using
                      the max function
           Code:

           # 9. max
           numbers_to_find_max = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
           print(“List Elements are:”,numbers_to_find_max)
           maximum_value = max(numbers_to_find_max)

           print(f”Maximum value in the list: {maximum_value}”)
           Explanation:
           1  The max() function is used to find the maximum value from a sequence (in this case, a list). In this example,
              the list numbers_to_find_max contains several numerical elements. The max() function is then applied to find
              and print the maximum value from the list.
           Output:












                                                           281

                              CITS : IT & ITES - Computer Software Application - Exercise 132
   291   292   293   294   295   296   297   298   299   300   301