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

COMPUTER SOFTWARE APPLICATION - CITS




           TASK 2:  Using Dictionary

           defprint_book_info(**book_details):
               “””
               This function takes book details as keyword arguments packed into a dictionary.
               Args:

                   **book_details: Book details (packed into a dictionary).
               “””
               print(“Book Information:”)
               for key, value inbook_details.items():
                   print(f”{key.capitalize()}: {value}”)
           # Example usage:

           print_book_info(title=”Wings of Fire “, author=”A. P. J. Abdul Kalam”, year=1999)
           Explanation :
           •  The function print_book_info is defined to accept any number of keyword arguments. The double-asterisk **
              before book_details allows the function to receive these keyword arguments and pack them into a dictionary
              called book_details.
           •  Inside the function, it prints “Book Information:” to indicate that it’s displaying information about a book.

           •  It then iterates through the key-value pairs in the book_details dictionary using a for loop. For each key-value
              pair, it prints the key (capitalized using capitalize()) and the corresponding value.
           •  The print_book_info function can handle different sets of book details, and the keys and values will be printed
              in a readable format.
           •  In the example usage, the function is called with specific book details for “Wings of Fire” by A. P. J. Abdul
              Kalam, published in 1999.
           Output:
















           TASK 3:  Using Tuple & Dictionaries
                 defprint_person_info(name, age, **additional_info):

                     “””
                     This function takes required positional arguments (name, age)
                     and additional keyword arguments packed into a dictionary.
                     Args:
                         name (str): Person’s name.

                         age (int): Person’s age.





                                                           268

                              CITS : IT & ITES - Computer Software Application - Exercise 129
   278   279   280   281   282   283   284   285   286   287   288