Page 307 - Touhpad Ai
P. 307

Output:
                     City: Mumbai  It's Population: 12442373
                     City: Delhi  It's Population: 11034555
                     City: Bangalore  It's Population: 8443675
                     City: Hyderabad  It's Population: 6993262
                     City: Chennai  It's Population: 4646732
                 17.   Write a program to read a list, display each element and its data type.
                     # Sample list with multiple types of values
                     input_list = [42, 3.14, "Hello", True, 78]

                     # Display each element and its type
                     for element in input_list:
                         print("Element:",element, "Type:",type(element))
                     Output:

                     Element: 42 Type: <class 'int'>
                     Element: 3.14 Type: <class 'float'>
                     Element: Hello Type: <class 'str'>
                     Element: True Type: <class 'bool'>

                     Element: 78 Type: <class 'int'>
                 18.   Write a Python program to print the words in a string which starts with the alphabet ‘T’ or ‘t’. Example: for the
                     string – ‘The tiger kept his kill in a tree’ we shall get output as The tiger tree

                     # Input string
                     input_string = 'The tiger kept his kill in a tree'
                     # Split the string into words
                     words = input_string.split()
                     # Iterate over the words and print those that start with 'T' or 't'
                     for word in words:
                         if word[0]=='T' or word[0]=='t':
                             print(word, end=' ')
                     Output:

                     The tiger tree
                 19.  Visualize the distribution of different types of transportation used by commuters in a city using a pie chart:
                        Car: 40%

                        Public Transit: 30%
                        Walking: 20%
                        Bicycle: 10%
                        import matplotlib.pyplot as plt
                        # Data
                        transport_modes = ['Car', 'Public Transit', 'Walking', 'Bicycle']
                        percentages = [40, 30, 20, 10]
                        # Create the pie chart
                        plt.figure(figsize=(8, 8))
                        plt.pie(percentages,  labels=transport_modes,  autopct='%1.1f%%',  colors=['red',
                        'pink ', 'green', 'orange'])

                                                                                                     Practical File  305
   302   303   304   305   306   307   308   309   310   311   312