horozov86

grocery list

Jun 6th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. def shop_from_grocery_list(budget, grocery_list, *products_and_prices):
  2.     bought_products = []
  3.     for product, price in products_and_prices:
  4.         if product not in grocery_list:
  5.             continue
  6.         if budget - float(price) < 0:
  7.             break
  8.         else:
  9.             bought_products.append(product)
  10.             grocery_list.remove(product)
  11.             budget -= float(price)
  12.     if not grocery_list:
  13.         return f"Shopping is successful. Remaining budget: {budget:.2f}."
  14.     else:
  15.         return f"You did not buy all the products. Missing products: {', '.join(grocery_list)}."
Add Comment
Please, Sign In to add comment