python编程从入门到实践:11-1城市与国家 11-2人口数量

个人答案,仅供参考
直接写出11-2

city_functions.py

def get_city_country(city,country,population=''):
    if population:
        full_name = city+','+country+'-population '+population
    else:
        full_name = city+','+country
    return full_name

test_cities.py

import unittest
from city_function import get_city_country

class CitiesTestCase(unittest.TestCase):
    """测试"""
    def test_city_country(self):
        """无面积的测试"""
        formatted_name = get_city_country('Hong Kong','Chian')
        self.assertEqual(formatted_name,'Hong Kong,Chian')

    def test_city_country_population(self):
        formatted_name = get_city_country('Taiwan','Chian','13.95亿')
        self.assertEqual(formatted_name,'Taiwan,Chian-population 13.95亿')

unittest.main()

python编程从入门到实践:11-1城市与国家 11-2人口数量_第1张图片

你可能感兴趣的:(python,编程)