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
The first step in planning effective writing is to consider the _____. Audience Style Purpose Main Idea
spin [16.1K]

Answer:

The first step in planning effective writing is to consider your creativity

Explanation:

4 0
3 years ago
Merge sort has a o(n log2(n)) complexity. if a computer can sort 1,024 elements in an amount of time x, approximately how long w
Musya8 [376]
<span>1,048,576 is 1,024 times 1,024, 1,024 * 1,024 or 1,024 squared or 1,024^2. If a computer takes x amount of time to sort 1,024 elements then the relationship is a 1 to 1. Therefore the computer will take x times x or x^2 (x squared) amount of time to sort 1,048,576.</span>
6 0
3 years ago
To keep your computer working efficiently, it is a good idea to _____ unnecessary files. delete defragment save archive
Korolek [52]

Hey the answer to this is delete or remove. because it is a good idea to remove old files that your not using.

Hope this helps

-scav

3 0
3 years ago
Editing is important because it allows you to
asambeis [7]
Answer A is the answer, as it combines all choices in the list. One can check the overall structure.
8 0
3 years ago
Random Pivot Selection: In the algorithm input elements are divided into groups of 5.
SSSSS [86.1K]

Answer:

A) The algorithm will work if they are divided into groups of 7

B ) If the groups of 3 are used they do not run in Linear time

Explanation:

ATTACHED TO THIS IS THE DETAILED PROVE OF  why the algorithm will work if they are divided into groups of 7 and also the prove that if groups of 3 are used they do not run in Linear time

3 0
3 years ago
Other questions:
  • A well-diversified portfolio needs about 20-25 stocks from different categories is this True or False?
    6·2 answers
  • How can a wiki contribute to an academic paper?
    9·2 answers
  • In what areas is leslie's underspending hurting her
    10·1 answer
  • Dit View
    5·2 answers
  • For which type of long-distance call do you need to tell the operator the name of the person to whom you wish to speak?
    10·1 answer
  • Can web sites contain copyright material? <br> Yes <br> No
    10·2 answers
  • Items that are cut or copied are placed on the Clipboard.
    6·2 answers
  • Question 5(Multiple Choice Worth 5 points)
    10·2 answers
  • 12. When computer professionals take on jobs, they may not enter into relationships with which of the
    6·1 answer
  • 10010 - 1011 binary subtraction​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!