In [1]:
class Circle(object):
    
    def __init__(self, r):
        self.radius = r
        
    def get_area(self):
        return 3.14 * self.radius * self.radius
        
    def get_length(self):
        return 3.14 * 2 * self.radius
    

c1 = Circle(10)
c2 = Circle(20)

print c1.get_area()
print c2.get_area()

print c1.get_length()
print c2.get_length()


314.0
1256.0
62.8
125.6

In [2]:
class BankAccount(object):
    def __init__(self, amount):
        self.amount = amount
        
    def withdraw(self, money):
        if self.amount >= money:
            self.amount -= money
        else:
            print "you can't"
        
    def save(self, money):
        self.amount += money
        
    def check(self):
        print 'deposit is', self.amount
        
    def check_interest(self, interest_month, duration_month):
        return self.amount * ((1 + interest_month) ** duration_month)
    
aaron = BankAccount(100000)
bob = BankAccount(1000)

aaron.save(1000000)
aaron.check()
print aaron.check_interest(0.1, 3)


deposit is 1100000
1464100.0

In [3]:
import datetime as dt

class VideoManager(object):
    def __init__(self):
        self.video_dict = {}
        
    def add_video(self, title, date = dt.datetime.now()):
        self.video_dict[title] = date
        
    def find_video(self, title):
        if title in self.video_dict:
            return title
        else:
            return 'no video named', title
        
    def is_new_release(self, title):
        now = dt.datetime.now()
        week_ago = now - dt.timedelta(days = 7)
        
        '''if self.video_dict[title] >= week_ago:
            return True
        else:
            return False'''
        
        return self.video_dict[title] >= week_ago
    
    
#print dt.datetime.now()
#print dt.datetime(2017, 1, 17, 18, 24, 0)

manager = VideoManager()
manager.add_video('transformer')
manager.add_video('abc', dt.datetime(2017, 1, 7, 18, 24, 0))

print manager.is_new_release('transformer')
print manager.is_new_release('abc')


True
False