livepython.net

230. Python Program to Calculate an Electricity Bill with Price Slabs

EasyPhase 1 · Warm-up

This one needs only if, elif and a little maths. You can do it.

Overview

Many power companies use price slabs. A slab is a band of units with its own price. The more power you use, the more each extra unit costs.

Problem Statement

Omar's power company uses these slabs:

  • The first 100 units cost 5 coins each.
  • The next 100 units (unit 101 to unit 200) cost 7 coins each.
  • Every unit above 200 costs 10 coins.

Read the number of units Omar used. Print Omar's bill as Bill: <total> coins.

Steps

  1. Read the units and turn them into a whole number.
  2. If the units are 100 or less, every unit costs 5 coins.
  3. Else, if the units are 200 or less, the first 100 units cost 500 coins, and each unit after that costs 7 coins.
  4. Else, the first 200 units cost 500 + 700 = 1200 coins, and each unit after that costs 10 coins.
  5. Print the bill.

Examples

Example 1. Input 80 gives:

Bill: 400 coins

Why: all 80 units are in the first slab, and 80 × 5 = 400.

Example 2. Input 250 gives:

Bill: 1700 coins

Why: 100 × 5 = 500, then 100 × 7 = 700, then 50 × 10 = 500. 500 + 700 + 500 = 1700.

Input

One whole number: the units used (0 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

One line: Bill: <total> coins. The tests try 6 different inputs, also 0, 100 and 200.

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

Finish this chapter firstChapter 8 · If Statements
solution.py
# write your code here

EXPECTED OUTPUT

1Bill: 400 coins

YOUR OUTPUT

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