fruitPrices = {'apples':2.00, 'oranges': 1.50, 'pears': 1.75, 'limes':0.75, 'strawberries':1.00} def buyLotsOfFruit(orderList): """ orderList: List of (fruit, numPounds) tuples Returns cost of order """ totalCost = 0.0 for fruit,prices in fruitPrices.items(): totalCost+=prices return totalCost # Main Method if __name__ == '__main__': "This code runs when you invoke the script from the command line" orderList = [ ('apples', 2.0), ('pears', 3.0), ('limes', 4.0) ] print 'Cost of', orderList, 'is', buyLotsOfFruit(orderList)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question