コード例 #1
0
def addCity():
    '''
    This function will add a new city 
    and all the relevant data about that city into existing cities.
    All the data is from user input
    '''
    cityName = raw_input("Please enter city name: \n")
    cityCode = raw_input("Please enter city code: \n")
    country = raw_input("Please enter country: \n")
    continent = raw_input("Please enter continent: \n")
    timezone = raw_input("Please enter timezone: \n")
    latitude = raw_input("Please enter latitude: \n")       # Type should be: S 30
    longitude = raw_input("Please enter longitude: \n")     # Type should be: W 30
    
    while True:         
        population = raw_input("Please enter population: \n")   #Check if the input is valid
        if int(population) > 0:
            break
        
    region = raw_input("Please enter region: \n")
    
    newCoordinates = UserQuerying.formCoordinate(latitude, longitude)   # Get the right format for the coordinates
    newCityInfo = CityInfo.CityInfo(cityCode, cityName, country, continent, int(timezone), newCoordinates, int(population), int(region))
    QueryingData.cityDicationary[cityName] = newCityInfo    # Add the new class into city Dictionary
    QueryingData.codeToName[cityCode] = cityName             # Add the code and the name into code to name dictionary
    UserQuerying.cityToContinent(cityName, continent)       # Add the city into right continent