KnowledgeBoat Logo

Computer Science

Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the names (in uppercase) of the places whose names are longer than 5 characters. For example, Consider the following dictionary:

PLACES = {1: "Delhi", 2: "London", 3: "Paris", 4: "New York", 5:"Doha"}

The output should be:

LONDON
NEW YORK

Python Dictionaries

2 Likes

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

Answered By

1 Like


Related Questions