Small projectIntermediate30 XPExercise 2/15

Shopping basket

Task

You have a budget of €1500. The program reads the prices of goods (whole euros, each on its own line) and adds them to the basket. Reading stops when 0 comes (end of shopping), or when the next item would exceed the budget - that item is not bought.

Then the program prints four lines:

1. how many items you bought, 2. how many of them are cheaper than the average price, 3. what the whole shopping cost, 4. the average price rounded to 2 decimal places.

If you bought nothing, it prints just 0.

What the program should do

For prices 200, 300, 500, 400 and 300 the first four are bought (1400 € in total); another 300 € would exceed the budget.

Examples

  • Input

    200
    300
    500
    400
    300

    Expected output

    4
    2
    1400
    350.00
  • Input

    100
    200
    0

    Expected output

    2
    1
    300
    150.00

After you submit, 5 hidden tests will also check your solution: exactly €1500, the first item is too expensive, no shopping, equal prices, an average with decimals.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.