livepython.net

238. Python Program to Scale a Recipe for More People

EasyPhase 1 · Warm-up

Only input(), int() and f-strings with :.2f are needed here, and you know them all.

Overview

Recipes are written for a set number of people. To cook for more or fewer people, you scale the recipe: you make every amount bigger or smaller by the same factor. A factor is the number you multiply by.

Problem Statement

Yuki has a pancake recipe for 4 people:

  • 200 g of flour
  • 300 ml of milk
  • 3 spoons of sugar

Read how many people Yuki will cook for. Print the 3 amounts for that many people, each with 2 decimal places, in this format:

Flour: <flour> g
Milk: <milk> ml
Sugar: <sugar> spoons

Steps

  1. Read the number of people and turn it into a whole number.
  2. Work out the factor: the people divided by 4.
  3. Multiply each amount of the recipe by the factor.
  4. Print the 3 lines with 2 decimal places.

Examples

Example 1. Input 6 gives:

Flour: 300.00 g
Milk: 450.00 ml
Sugar: 4.50 spoons

Why: 6 ÷ 4 = 1.5, so every amount is 1.5 times bigger. 200 × 1.5 = 300, 300 × 1.5 = 450, and 3 × 1.5 = 4.5.

Example 2. Input 1 gives:

Flour: 50.00 g
Milk: 75.00 ml
Sugar: 0.75 spoons

Why: 1 ÷ 4 = 0.25, so every amount is a quarter of the recipe. 200 × 0.25 = 50, 300 × 0.25 = 75, and 3 × 0.25 = 0.75.

Input

One whole number: the number of people (1 or more). Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

3 lines, as shown above, each amount with 2 decimal places. The tests try 6 different inputs, also 4, where the amounts do not change.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 7 · Getting Input from the User
solution.py
# write your code here

EXPECTED OUTPUT

1Flour: 300.00 g
2Milk: 450.00 ml
3Sugar: 4.50 spoons

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.