diff --git a/recipe_batches/recipe_batches.py b/recipe_batches/recipe_batches.py index c845950c5..2e33bc5b4 100644 --- a/recipe_batches/recipe_batches.py +++ b/recipe_batches/recipe_batches.py @@ -3,12 +3,21 @@ import math def recipe_batches(recipe, ingredients): - pass + cake_batches = 0 + for key, value in recipe.items(): + if key not in ingredients or ingredients[key] < value: + cake_batches = 0 + break + something = ingredients[key] // value + if cake_batches > 0 and something > cake_batches: + continue + cake_batches = something + return cake_batches if __name__ == '__main__': - # Change the entries of these dictionaries to test + # Change the entries of these dictionaries to test # your implementation with different inputs recipe = { 'milk': 100, 'butter': 50, 'flour': 5 } ingredients = { 'milk': 132, 'butter': 48, 'flour': 51 } - print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients)) \ No newline at end of file + print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients)) diff --git a/stock_prices/stock_prices.py b/stock_prices/stock_prices.py index 9de20bc94..5577d2be3 100644 --- a/stock_prices/stock_prices.py +++ b/stock_prices/stock_prices.py @@ -3,8 +3,15 @@ import argparse def find_max_profit(prices): - pass + maximum = max(prices) + max_index = prices.index(maximum) + if max_index == 0: + maximum = max(prices[1:]) + max_index = prices.index(maximum) + minimum = min(prices[:max_index]) + + return maximum - minimum if __name__ == '__main__': # This is just some code to accept inputs from the command line @@ -12,4 +19,4 @@ def find_max_profit(prices): parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer price') args = parser.parse_args() - print("A profit of ${profit} can be made from the stock prices {prices}.".format(profit=find_max_profit(args.integers), prices=args.integers)) \ No newline at end of file + print("A profit of ${profit} can be made from the stock prices {prices}.".format(profit=find_max_profit(args.integers), prices=args.integers))