Skip to content
This repository was archived by the owner on Jul 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions recipe_batches/recipe_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
print("{batches} batches can be made from the available ingredients: {ingredients}.".format(batches=recipe_batches(recipe, ingredients), ingredients=ingredients))
11 changes: 9 additions & 2 deletions stock_prices/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
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
parser = argparse.ArgumentParser(description='Find max profit from 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))
print("A profit of ${profit} can be made from the stock prices {prices}.".format(profit=find_max_profit(args.integers), prices=args.integers))