Calculations

Calculate electricity power:Python program using function

Calculate Electricity power: Python program using function

In this tutorial, we will discuss the Calculate Electricity power: Python program using the function

In this article, we will discuss how to calculate monthly  electricity bill using the function in the Python  programming language

We can calculate monthly electric power usage in many approaches in Python language

 

In this tutorial, we have written two programs for calculating electricity cost using the function in Python language

Calculate electricity power: Python program

Before we write a program to calculate the electricity bill we must understand electricity charges and rates.

/*1 - 50 unit - 1.50/= 
  51-150 unit - 2.00/= 
  151-250 unit - 3.00/= 
above 250 - 4.00/=*/

 

In my previous post, I have explained the various approaches to Calculate electricity bill in Python language

However, in this program, we embed the logic of the electricity bill calculation program in the function

Once this program received the units and it will calculate the electricity bill and cost per month

After receiving the input from the user, it is stored in the variable of the unit and then the program calculates electricity bill

 

This program has the following steps for completion of this program

  • Declare total unit consumed by the customer using the variable unit.
  • If the unit consumed less or equal to 50 units, calculates the total amount of usage =unit*1.50
  • If the unit consumed between 50 to 150 units, calculates the total amount of usage =(50*1.5)+(unit-50)*2)
  • If  unit consumed between 150 to 250 units ,calculates total amount of usage =(50*1.5)+(100)*2)+(unit-150)*3
  • If unit consumed above 250 units ,calculates total amount of usage =(50*1.5)+(100)*2)+(100)*3+(unit-250)*4
  • No additional charge

Program 1

Without and operator

#in this program, we displayed how to calculate electricity bill
unit=int(input("Enter the unit consumed: "))
#//Reads input from user and store in variable num

def Bill_Calc(unit):#function definition
    
    if(unit<=50):
          #below 50 units
        print(unit*1.50);

    
    elif(unit<=150):
           #below 150 units
        print((50*1.5)+(unit-50)*2.00);
    
    elif((unit<=250)):#below 250 units
        print((50*1.5)+((150-50)*2.00)+(unit-150)*3.00);
    
    else:   #above 250 units
        print((50*1.5)+((150-50)*2.00)+((250-150)*3.00)+(unit-250)*4);

Bill_Calc(unit)#function call

When the above code is executed, it produces the following results

Enter the unit consumed: 300
775.0

 

Program 2

with and operator

unit=int(input("Enter the unit consumed: "))

def Bill_Calc1(unit):          #function definition
    if((unit>=1)and(unit<=50)):#between 1 - 50 units
        print(unit*1.50);
    
    elif((unit>50)and(unit<=150)):#between 50 - 150 units
    
        print((50*1.5)+(unit-50)*2.00)
    
    elif((unit>150)and(unit<=250)):#between 150 -  250 units
        print((50*1.5)+((150-50)*2.00)+(unit-150)*3.00)
    
    elif(unit>250):           #above 250 units
        print((50*1.5)+((150-50)*2.00)+((250-150)*3.00)+(unit-250)*4)

    else:
            print("No usage ");
        #amount=0;
Bill_Calc1(unit)             #function call

When the above code is executed, it produces the following results

Enter the unit consumed: 450
1375.0

 

Similar post

C++ code to calculate electricity bill

C code to calculate electricity bill

Java code to calculate electricity bill

Python program to calculate electricity bill

C++ program to calculate electricity bill using function

C program to calculate electricity bill using function

Java program to calculate electricity bill using method

Python program to calculate electricity bill using function

 

Suggested for you

Operator in C++ language

If statement in C++ language

Type of User-define function in C++ language

 

Operator in C language

If statement in C language

scanf()  print() function

Function in C language

User define function in C language

 

Operator in Python language

If statement in Python language

Function in Python language

 

 

 

C program to Electricity bill calculation using function
Calculate power of a number using recursion in C language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago