Skip to content

Instantly share code, notes, and snippets.

@Arthraim
Created January 21, 2014 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arthraim/8535576 to your computer and use it in GitHub Desktop.
Save Arthraim/8535576 to your computer and use it in GitHub Desktop.
我只是想看看用哪个联通套餐最便宜
# coding:utf-8
def calc(p_count, p_price, m_count, m_price, w_count, w_price, t_p_count, t_m_count, t_w_count, t_price):
"""计算各套餐价格
p_count -- 通话时间(分钟)
p_price -- 通话价格
m_count -- 短信(条)
m_price -- 短信价格
w_count -- 流量(mb)
w_price -- 流量价格
t_p_count -- 套餐内通话时间
t_m_count -- 套餐内短信数
t_w_count -- 套餐内流量数
t_price -- 套餐价格
"""
sum, p_sum, m_sum, w_sum = (0, 0, 0, 0)
if p_count > t_p_count:
p_sum = (p_count - t_p_count) * p_price
sum = sum + p_sum
if m_count > t_m_count:
m_sum = (m_count - t_m_count) * m_price
sum = sum + m_sum
if w_count > t_w_count:
w_sum = (w_count - t_w_count) * w_price
sum = sum + w_sum
return t_price + sum, p_sum, m_sum, w_sum
def print_all(p_count, m_count, w_count):
"""打印各套餐价格
p_count -- 通话时间(分钟)
m_count -- 短信(条)
w_count -- 流量(mb)
"""
w_count = w_count - 500
print '46 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 50, 0, 150, 46)[0] - 30)
print '66 -> %d' % (calc(p_count, 0.2, m_count, 0.1, w_count, 0.3, 50, 240, 300, 66)[0] - 30)
print '96 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 240, 0, 300, 96)[0] - 30)
print '126 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 320, 0, 400, 126)[0] - 30)
print '156 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 420, 0, 500, 156)[0] - 30)
print '186 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 510, 0, 650, 186)[0] - 30)
print '226 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 700, 0, 750, 226)[0] - 30)
print '286 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 900, 0, 950, 286)[0] - 30)
print '386 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 1250, 0, 1300, 386)[0] - 30)
print '586 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 1950, 0, 2000, 586)[0] - 30)
print '886 -> %d' % (calc(p_count, 0.25, m_count, 0.1, w_count, 0.3, 3000, 0, 3000, 886)[0] - 30)
print '12月'
print_all(419, 100, 1000)
print '11月'
print_all(1020, 100, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment