CBSE Class 12 Computer Science Question 52 of 56

Functions — Question 52

Back to all questions
52
Question

Question 45

Write a method COUNTNOW(PLACES) to find and display those place names in which there are more than 5 characters after storing the name of places in a dictionary. For example, if the dictionary PLACES contains:

{'1': "DELHI", '2': "LONDON", '3': "PARIS", '4': "NEW YORK", '5': "DUBAI"}

The following output should be displayed:
LONDON
NEW YORK

Solution
PLACES = {1: "Delhi", 2: "London", 3: "Paris", 4: "New York", 5: "Doha"}
def countNow(PLACES):
    for place in PLACES.values():
        if len(place) > 5:
            print(place.upper())
countNow(PLACES)
Output
LONDON
NEW YORK
Answer

PLACES
=
{
1
:
"Delhi"
,
2
:
"London"
,
3
:
"Paris"
,
4
:
"New York"
,
5
:
"Doha"
}
def
countNow
(
PLACES
):
for
place
in
PLACES
.
values
():
if
len
(
place
)
>
5
:
print
(
place
.
upper
())
countNow
(
PLACES
)
Output
LONDON
NEW YORK