Skip to content

Instantly share code, notes, and snippets.

@kuozo
Created December 18, 2013 10:24
Show Gist options
  • Save kuozo/8020161 to your computer and use it in GitHub Desktop.
Save kuozo/8020161 to your computer and use it in GitHub Desktop.
#!/usr/bin python
# coding: utf-8
'''
Simple Script for iPhone Price.
'''
__author__ = 'Kollin'
class PhoneCost(object):
def __init__(self, h_price, c_price, u_price, cycle, b_price):
'''
h_price: Hong Kong iPhone Price
c_price: China Unicom iPhone Price
u_price: cost every month
cycle: such as 12, 24, 30
b_price: China Unicom back price for every month
'''
self.h_price = h_price
self.c_price = c_price
self.u_price = u_price
self.cycle = cycle
self.b_price = b_price
def cal_h_cost(self):
return self.h_price + self.u_price * self.cycle
def cal_c_cost(self):
return self.c_price + (self.u_price - self.b_price) * self.cycle
def compare(self):
h_cost = self.cal_h_cost()
c_cost = self.cal_c_cost()
print 'Hong Kong: {0}'.format(h_cost)
print 'China Unicom: {0}'.format(c_cost)
return "Hong Kong Better" if h_cost < c_cost else 'China Unicom Better'
if __name__ == '__main__':
print 'When cost 66 every month.'
pc = PhoneCost(4400, 5499, 66, 30, 46)
print pc.compare()
print
print 'When cost 96 every month.'
pc = PhoneCost(4400, 5499, 96, 30, 66)
print pc.compare()
print
print 'When cost 126 every month.'
pc = PhoneCost(4400, 5499, 126, 30, 73)
print pc.compare()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment