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

COMPUTER SOFTWARE APPLICATION - CITS




           Explanation:
           1  List to Tuple Conversion: The program creates a list example_list containing integers.
           2  Tuple Creation: The tuple() function is used to convert the list into a tuple. The resulting tuple is assigned to
              the variable tuple_from_list.
           3  Display: The program prints the tuple obtained from the list using the print statement. The formatted string
              (f”...”) is used to include the tuple in the output.

           Output:













           TASK 14 :  Write a program that uses the vars function  to display all  variables in  the program as
                            a dictionary
           Code:
           # 14. vars

           name = “John”
           age = 25
           country = “USA”
           info_dict = vars()
           print(f”Variables as dictionary: {info_dict}”)
           Explanation:

           1  Variable Information: The program defines three variables: name, age, and country.
           2  vars() Function: The vars() function is used to obtain a dictionary representing the current local symbol table.
              This includes all variables currently defined.

           3  Display: The program prints the dictionary obtained from the local variables using the print statement. The
              formatted string (f”...”) is used to include the dictionary in the output.
              These examples showcase how to convert a list to a tuple and how to obtain variable information as a dictionary
              using the vars() function. The output will display the converted tuple and the dictionary of local variables.
           Output:

























                                                           284
                              CITS : IT & ITES - Computer Software Application - Exercise 132
   294   295   296   297   298   299   300   301   302   303   304