p6p
4/13/2015 - 3:13 PM

homework

#!/usr/bin/env python
# coding=utf-8
# 計算工概作業第四題

# 賣出個數的機率
p = [0.0025, 0.0149, 0.0446, 0.0892,
     0.1339, 0.1606, 0.1606, 0.1377,
     0.1033, 0.0688, 0.0413, 0.0225,
     0.0113, 0.0052, 0.0022, 0.0014]

def profit(c):
	"""
	c: 製作個數
	return 收益
	"""
	sum = 0
	for x in xrange(16):
		if c > x:
			sum += (12 * x + 0.5 * 9 * (c - x)) * p[x]
		else:
			sum += 12 * c * p[x]
	return sum

def main():
	for x in xrange(16):
		# 輸出收益減成本
		outcome = profit(x) - 9 * x
		print "%d =>\t%10.2f" %(x, outcome)

if __name__ == '__main__':
	main()