tutorial7 function



In [5]:
if 0 == 1: 
    print 'We are in a world of arithmetic pain' 
print 'Thank you for playing'


Thank you for playing

In [6]:
if 0 == 1: 
    print 'We are in a world of arithmetic pain'
    print 'Thank you for playing'

In [7]:
fruitPrices = {'apples':2.00, 'oranges': 1.50, 'pears': 1.75}

In [8]:
def buyFruit(fruit, numPounds):
    if fruit not in fruitPrices:
        print "Sorry we don't have %s" % (fruit)
    else:
        cost = fruitPrices[fruit] * numPounds
        print "That'll be %f please" % (cost)

In [9]:
# Main Function
if __name__ == '__main__':        
    buyFruit('apples',2.4)
    buyFruit('coconuts',2)


That'll be 4.800000 please
Sorry we don't have coconuts

In [ ]: