高级编程技术 第六周作业

24人阅读 评论(0) 收藏 举报
分类:

第十一章

11.1

city_functions.py

def get_city_country(city, country):
	city_country = city + ', ' + country
	
	return city_country.title()

test_cities.py

import unittest
from city_functions import get_city_country

class City_Country_TestCase(unittest.TestCase):
	
	def test_get_city_country(self):
		city_country = get_city_country('santiago', 'chile')
		self.assertEqual(city_country, 'Santiago, Chile')

unittest.main()

11.2

city_functions.py

def get_city_country(city, country, population):
	city_country = city + ', ' + country + ' - population ' + str(population)
	
	return city_country.title()

test_cities.py

import unittest
from city_functions import get_city_country

class City_Country_TestCase(unittest.TestCase):
	
	def test_get_city_country(self):
		city_country = get_city_country('santiago', 'chile')
		self.assertEqual(city_country, 'Santiago, Chile')

unittest.main()

city_functions.py

def get_city_country(city, country, population = 0):
	if population:
		city_country = city.title() + ', ' + country.title() + ' - population ' + str(population)
	else:
		city_country = city.title() + ', ' + country.title()
	return city_country

test_cities.py

import unittest
from city_functions import get_city_country

class City_Country_TestCase(unittest.TestCase):
	
	def test_get_city_country(self):
		city_country = get_city_country('santiago', 'chile')
		self.assertEqual(city_country, 'Santiago, Chile')

unittest.main()

city_functions.py

def get_city_country(city, country, population = 0):
	if population:
		city_country = city.title() + ', ' + country.title() + ' - population ' + str(population)
	else:
		city_country = city.title() + ', ' + country.title()
	return city_country

test_cities.py

import unittest
from city_functions import get_city_country

class City_Country_TestCase(unittest.TestCase):
	
	def test_get_city_country(self):
		city_country = get_city_country('santiago', 'chile')
		self.assertEqual(city_country, 'Santiago, Chile')

	def test_city_country_population(self):
		city_country_population = get_city_country('santiago', 'chile', 5000000)
		self.assertEqual(city_country_population, 'Santiago, Chile - population 5000000')

unittest.main()

11.3

Employee.py

class Employee():
	def __init__(self, first, last, salary):
		self.first = first
		self.last = last
		self.salary = salary

	def give_raise(self, raises = 5000):
		self.salary += raises

Test_Employee.py

import unittest
from city_functions import Employee
class TestEmployee(unittest.TestCase):
	def setUp(self):
		self.test_data = Employee('Jack', 'Black', 10000)

	def test_give_default_raise(self):
		self.test_data.give_raise()
		self.assertEqual(15000, self.test_data.salary)

	def test_give_custom_raise(self):
		self.test_data.give_raise(3000)
		self.assertEqual(13000, self.test_data.salary)

unittest.main()

查看评论

高级编程技术_课后作业(一)

一、浏览Python主页的发现与收获            Python的主页(https://www.python.org/)挺简洁的,内容很丰富,有Python解释器的下载、131212个Pyth...
  • Zero_S_Qiu
  • Zero_S_Qiu
  • 2018-03-05 19:55:47
  • 62

高级编程技术,第一周

1.浏览python首页的收获:浏览python首页,可以很直观的看到python的各种特性以及python的广泛应用,尤其是python庞大的库,让我认识到了python与之前学过的C++,C的不同...
  • qq_36319729
  • qq_36319729
  • 2018-03-05 22:28:01
  • 26

2008061023_CC_第六周作业

  • 2011年04月04日 09:53
  • 168KB
  • 下载

高级编程技术第一次作业

一、浏览Python主页,我有哪些发现和收获?        1、官网可以加载一个类似命令行的窗口直接执行python代码,不过速度有点慢,给我感觉比较鸡肋。        2、官网的Document...
  • qq_39178023
  • qq_39178023
  • 2018-03-05 18:00:00
  • 33

第一次作业(高级编程技术)

1.python主页上的发现和收获。python主页上除了基本的下载和介绍外,还有三个地方让我收获颇多。1.主页上有一个在线的编译器,可以完成python 的基本任务,而且他会随机的出现一些简单的py...
  • qq_24982579
  • qq_24982579
  • 2018-03-05 18:45:36
  • 27

【高级编程技术】第六周作业

11-1:11-2:11-3:
  • Ivyseike
  • Ivyseike
  • 2018-04-10 14:44:20
  • 19

《高级编程技术》第六周作业

11-1 城市和国家:①name_function.py:def get_name(city, country): return city.title() + ', ' + country.titl...
  • weixin_36348299
  • weixin_36348299
  • 2018-04-15 20:46:48
  • 3

高级编程技术 课后作业一

一、浏览Python主页(https://www.python.org/),在博客上写下你有哪些发现和收获。    Python主页的设计风格就如同语言本身一样简洁明了,界面没有过多的装饰性元素,内容...
  • static_check
  • static_check
  • 2018-03-08 09:59:56
  • 28

高级编程技术第六周作业

11.1city_functions.pydef get_city_country(City,Country): return City+", "+Countrytest_cit...
  • liangjan
  • liangjan
  • 2018-04-15 16:38:10
  • 2

高级编程技术 课后作业七(第4周)

7-1 汽车租赁 :编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如“LetmeseeifIcan find you a Subaru”。car = input("What ki...
  • static_check
  • static_check
  • 2018-03-26 11:29:00
  • 16
    个人资料
    等级:
    访问量: 1301
    积分: 75
    排名: 142万+
    文章分类
    文章存档