1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
evablogger [386]
3 years ago
7

Create a class CitiesAndCountries with at least three methods: class CitiesAndCountries: def add_country(self, country_name): ""

" :param country_name: name of new country :return: True if added, False if duplicate """ def add_city(self, country_name, city_name): """ :param country_name: must be a country in the already defined countries :param city_name: name of new city. :return: True if added, False if not added """ def find_city(self, city_name): """ :param city_name: get all cities with that name, in all different countries :return: list of countries which have a city with that name, empty list if none """
Computers and Technology
1 answer:
sveticcg [70]3 years ago
6 0

Answer:

Check the explanation

Explanation:

class CitiesAndCountries:

   """

   This is the class which maintains a dictionary of the Countries with the cites in them.

   """

   def __init__(self):

       """

       Constructor for the class CitiesAndCountries.

       It defines a dictionary to store the names of the countries and a list of the cities which are in them

       Example of the the following dictionary when it is populated:

       citiesandcountries = {"india":["bhopal", "mumbai", "nagpur"], "usa":["new york", "seatlle"]

       Keeping the names in lowercase helps in search

       """

       self.citiesandcountries = {}  # This is the dictionary which stores the information

   def add_country(self, country_name):

       """

       The add_country function to add countries to our list.

       :param country_name: Name of the country to add to the dictionary

       :return: True if added to the dictionary, False if it is already present in the dictionary

       """

       if country_name.lower() not in self.citiesandcountries.keys():

           self.citiesandcountries[country_name.lower()] = [] # Storing the country name in lower case helps in

           # searching

           return True

       else:  # You could omit the else statement and directly return False, but it adds to readability.

           return False

   def add_city(self, country_name, city_name):

       """

       This function adds the cities names to the dictionary corresponding to their countries.

       :param country_name: Country to which the city belongs

       :param city_name:  Name of the city to be added

       :return: True if the country is present in the dictionary and the city is added to the list, else False

       """

       if country_name.lower() in self.citiesandcountries.keys():

           self.citiesandcountries[country_name.lower()].append(city_name.lower())

           return True

       else:

           return False

   def find_city(self, city_name):

       """

       This function is used to retrive a list of countries where the city with the given name is present

       :param city_name: Name of the city.

       :return: A list of all the countries where the city if present.

       """

       countries_with_city = []

       for country in self.citiesandcountries.keys():

           if city_name.lower() in self.citiesandcountries[country]:

               countries_with_city.append(country.title())

       return countries_with_city

You might be interested in
What is the best method for modern businesses to authorize the use of workplace resources to its employees? a. assign them a use
Zielflug [23.3K]

The best method for modern businesses to authorize the use of workplace resources to its employees is to assign them a user authentication and password.

What is user authentication and password?

This is known to be what identifies a user when using the computer system or others.

Note that in the above, The best method for modern businesses to authorize the use of workplace resources to its employees is to assign them a user authentication and password.

Learn more about businesses from

brainly.com/question/24553900

#SPJ4

6 0
2 years ago
The NFiPA 704 system uses a numerical value between _____ and _____ to indicate the level of hazard for that particular chemical
Lena [83]

d would be your answer....................................

3 0
3 years ago
Read 2 more answers
A(n) ____________________ is the collection of individuals responsible for the overall planning and development of the contingen
RSB [31]

Answer:

Contingency Planning Management Team (CPMT)

Explanation:

:)

3 0
3 years ago
What does ascii stand for?
tamaranim1 [39]
ASCII—American Standard Code for Information Interchange
7 0
3 years ago
Read 2 more answers
A time-saving strategy that helps define unfamiliar words involves using
yuradex [85]

The correct answer is A. Familiar words for clues

Explanation:

Finding unfamiliar words is common while reading, especially in texts that belong to a specific field such as medicine, technology, etc. This can be handled through multiple strategies such as using a dictionary, guessing the meaning of the word based on its parts, and using context clues.

In this context, one of the easiest and most time-saving strategy is the use of context clues that implies using the familiar words as clues to guess the meaning of an unfamiliar word. This is effective because in most cases the meaning of an unknown word can be determined using the context of the word or words around the unknown word. Also, this strategy takes little time because you only need to analyze the sentence or paragraph where the unknown word is. Thus, the time-saving strategy to define unfamiliar words involves using familiar words for clues.

6 0
3 years ago
Read 2 more answers
Other questions:
  • based on the transcript, what did broadcasting the story through the medium of radio allow welles to do?
    8·1 answer
  • How to save customised keyboard shortcuts on word
    11·1 answer
  • When you want to print a page from the World Wide Web, select the print command in the _____.
    8·2 answers
  • Develop a Python module that will prompt the user for a target sum that is greater than 0 and less than 1 for the following Geom
    13·1 answer
  • How to attach a picture on brainily?
    8·1 answer
  • There are how many GPS satellites orbiting the earth
    15·1 answer
  • 3.2 lesson practice edhesive ​
    6·1 answer
  • What is c also write it's features
    8·2 answers
  • HELP PLSSSSS!!! I WILL MARK BRAINLIEST FOR THE FIRST AND CORRECT ANSWER!!!
    14·2 answers
  • The physical parts of a computer are called application software.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!