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()
标签:11,city,name,python,country,self,formatted,人口数量,population 来源: https://blog.csdn.net/weixin_41510592/article/details/99698201