You will write three small functions about ratios and best value. The checker uses a prize, a recipe and two packs of rice.
The idea. A ratio is in simplest form when its parts share no common factor. To share an amount, divide it by the number of parts and multiply. To compare packs, compare the price for one gram.
Your tasks.
simplest(a, b). Return the ratio in simplest form as a pair. Use gcd from the math module.share(total, parts). Return a list with each person's share.better_value(price1, grams1, price2, grams2). Return 1 if the first pack costs less per gram, and 2 otherwise.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…