Page 434 - AI_Ver_3.0_class_11
P. 434
7. Create a dictionary which will store names of Indian cities and their respective population. Display the data of the
dictionary.
cities = {
"Mumbai": 12442373,
"Delhi": 11034555,
"Bangalore": 8443675,
"Hyderabad": 6993262,
"Chennai": 4646732
}
for city, population in cities.items():
print("City:", city, " It's Population:",population)
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
8. Write a program to read a list, display each element and its data type. [CBSE Handbook]
# 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'>
9. 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
432 Touchpad Artificial Intelligence (Ver. 3.0)-XI

