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('*','Chian')
        self.assertEqual(formatted_name,'*,Chian')

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

unittest.main()

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

上一篇:FIT5147 数据探索和可视化 学习笔记


下一篇:php – 显示完整的国名,而不是国家代码 – WooCommerce