Exemple #1
0
def get_country():
    """
    get the country of the user
    return  value is country name
    """
    
    country = ""
    #if back is False, loop will start
    while not back[0]:
        
        #get input
        country = raw_input("\nEnter the country you are from (either country code or country name): ")

        #if input \\b (back), set back to True
        if country == "\\b":
            back[0] = True
            return True

        #else continue in validating input
        else:
            #validating input using country_exist() 
            if c.country_exist(country) == False:
                print ("Error, invalid country code or country name not found.")
            else:
                return c.country_exist(country)
Exemple #2
0
def get_acceptable_country():
    """
    get the acceptable country
    return a list of country name
    """
    
    acceptableCountryList = []
    #if back is False, loop will start
    while not back[0]:
        
        #get input
        print "\nCan be mixture of country name and country code"
        acceptable_country = raw_input("Enter your acceptable country, separate by (,): ")

        #if input \\b (back), set back to True
        if acceptable_country == "\\b":
            back[0] = True
            return True

        #else continue in validating input
        else:
            #split input by ','
            acceptable_country = acceptable_country.split(",")

            #loop each country and check if is valid country name or country code
            #valid country will be append into acceptableCountryList
            #if one is invalid, acceptableCountryList will be cleared and ask for input again
            for eachCountry in acceptable_country:
                eachCountry = eachCountry.strip()
                if c.country_exist(eachCountry) == False:
                    acceptableCountryList = []
                    print ("Error, one or more country name or country code is invalid.")
                    break
                else:
                    acceptableCountryList.append(c.country_exist(eachCountry))

            #if above forloop never break, confirm the amount of country appended is same as what user gave
            #if nothing wrong, remove duplicate country names, return result
            if len(acceptableCountryList) == len(acceptable_country):
                return list(set(acceptableCountryList))