shopping_list = ["banana", "orange", "apple"] stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15 } prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3 } # Write your code below! def compute_bill(food): total = 0 for item in food: if stock[item] > 0: print 'we\'ve added 1 ' + item + ' to your cart' print 'your total is now: $' + str(total) # print stock[item] stock[item] -= 1 # print stock[item] total += prices[item] print else: print 'sorry, we are currently out of ' + item + 's!' print 'your total is: $' + str(total) print 'total: ' + str(total) compute_bill(shopping_list)
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