Day 05 - Python Homework

If-Else, Switch-Case, and Electricity Bill Calculator

Practice Python to improve your coding skills. Use VS Code and create the files below. Run each program and check the output.

Remember to save your files with a .py extension and run them to see the output!

Assignment 01: If-Else Syntax Practice

Understand the basic structure of the if-else statement.

Objective:

Learn how to use the if-else statement in Python by practicing basic conditional checks.

Assignment 02: Switch-Case Syntax Practice

Understand the basic structure of the switch-case statement in other languages and simulate it in Python using if-elif-else.

Objective:

Learn how to simulate a switch-case structure using if-elif-else statements in Python.

Assignment 03: Electricity Bill Calculator (If-Else)

To calculate the electricity bill amount based on the number of units consumed, apply different slab rates using if-else conditions, and display the total bill amount with a suitable message.

Objective:

Learn how to calculate the electricity bill based on units consumed and apply appropriate if-else conditions for the bill calculation.

Instructions:

  • Ask the user to enter the number of electricity units consumed.
  • Using if-else conditions, calculate the bill as per the following rules:
    • If units are ≤ 100, cost = units * ₹1
    • If units are > 100 and ≤ 300, cost = 100 * ₹1 + (units - 100) * ₹2
    • If units are > 300, cost = 100 * ₹1 + 200 * ₹2 + (units - 300) * ₹3
  • If the bill amount is more than ₹1000, display: "High usage! Please save electricity"
  • Otherwise, display: "Thank you for saving electricity"
  • Show the total units consumed and the final bill amount clearly.
Bonus Challenge: Add a feature to display a discount if the user consumes less than 100 units.

If you need help

Post in the group with any of these problems:

Good luck and have fun coding!