Quotes help make search much faster. Example: "Practice Makes Perfect"

Sunday, December 9, 2012

LearnStreet Python Lesson 9 Exercise 8


#sample solution


def run(bottle):
    #your code here
    bottle.drink(250)
    bottle.refill(150)
    return bottle.amount_left

class Bottle:
    def __init__(self, liquid):
        self.amount= 500
        self.height = 10
        self.empty = False
        self.liquid = liquid
    def amount_left(self):
        return self.amount
    def drink(self, amount):
        if amount < self.amount:
            self.amount -= amount
        elif amount == self.amount:
            self.amount -= amount
            self.empty = True
        else:
            print "Cannot drink more " + self.liquid + " than there is!"
    def refill(self, amount):
        if amount + self.amount > 500:
            print "Cannot add that much " + self.liquid + " to the bottle!"
        else:
            self.amount += amount
            self.empty = False

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts