def biggest_number(*args): print max(args) return max(args) def smallest_number(*args): print min(args) return min(args) def distance_from_zero(arg): print abs(arg) return abs(arg) biggest_number(-10, -5, 5, 20) smallest_number(-10, -5, 5, 10) distance_from_zero(-10) prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3 } stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15 } ''' for fruit in prices: print fruit print "price: %s" % prices[fruit] print "stock: %s" % stock[fruit] total = 0 for key in prices: print prices[key]*stock[key] total = total + prices[key]*stock[key] print total ''' shopping_list = ["banana", "orange", "apple"] def compute_bill(food): total = 0 for i in food : if stock[i] > 0: total += prices[i] stock[i] = stock[i] - 1 print 'the total is ' + 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