python-checkio/Elementary/best-stock.py

19 lines
574 B
Python

def best_stock(a):
max_value = 0
best = None
for k, v in a.items():
if v > max_value:
max_value = v
best = k
return best
if __name__ == '__main__':
print("Example:")
print(best_stock({"CAC": 10.0, "ATX": 390.2, "WIG": 1.2}))
# These "asserts" are used for self-checking and not for an auto-testing
assert best_stock({"CAC": 10.0, "ATX": 390.2, "WIG": 1.2}) == "ATX"
assert best_stock({"CAC": 91.1, "ATX": 1.01, "TASI": 120.9}) == "TASI"
print("Coding complete? Click 'Check' to earn cool rewards!")