{"id":12494,"date":"2021-09-30T11:30:28","date_gmt":"2021-09-30T06:00:28","guid":{"rendered":"https:\/\/python-programs.com\/?p=12494"},"modified":"2021-11-22T18:35:29","modified_gmt":"2021-11-22T13:05:29","slug":"python-program-to-calculate-electricity-bill","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-electricity-bill\/","title":{"rendered":"Python Program to Calculate Electricity Bill"},"content":{"rendered":"
Explore complete java concepts from the Java programming examples<\/a> and get ready to become a good programmer and crack the java software developer interview with ease.<\/p>\n In this article, we will create a Python program that will assist us in calculating our electricity cost based on the inputs and conditions we provide. Keep in mind that conditions are not constant, as electricity rates vary from location to location. You can create your own program by adjusting the unit cost based on your present area.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to Calculate the Electricity Bill in Python.<\/p>\n Approach:<\/strong><\/p>\n Give the number of units consumed as static input and store it in a variable.<\/p>\n Here, I’m using the Indian Rupee (Rs) as the currency, and the requirements are as follows:<\/p>\n If the number of units used equals 100, the cost per unit is Rs 3.46. Using If Else statements we check the conditions and calculate the cost per unit.<\/p>\n After Calculating cost per unit we multiply the number of units by 1.45 and add it to the bill(Adding monthly line rent to the bill)<\/p>\n We add Rs 100 to the bill as additional fixed meter rent.<\/p>\n We multiply the present bill amount by 0.16 (Adding the tax) and add this bill to the past bill.<\/p>\n Print the Final Electricity Bill.<\/p>\n The Exit of the Program.<\/p>\n Below is the Implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the Implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease. In this article, we will create a Python program that will assist us in calculating our electricity cost based on the inputs and conditions we provide. Keep in mind …<\/p>\nGiven number of units = 176<\/pre>\n
The Electricity bill for the units 176 = 1468.4207999999999<\/pre>\n
Given number of units = 259<\/pre>\n
The Electricity bill for the units 259 = 2323.3871999999997<\/pre>\n
Python Program to Calculate Electricity Bill<\/h2>\n
\n
Method #1:Using If\u00a0 Else Statement (Static Input)<\/h3>\n
\nIf the number of units used is greater than 101 and less than 300, the cost per unit is Rs 7.43.
\nIf you consume more than 301 units and less than 500 units, the cost per unit is Rs 10.32.
\nIf the number of units consumed exceeds 501, the cost per unit is Rs 11.71.
\nThe monthly line rent is Rs 1.45 per unit.
\nThe additional fixed meter\u00a0rent is Rs 100.
\nThe tax on the bill is 16%, which is equal to 0.16.<\/p>\n# Give the number of units consumed as static input and store it in a variable.\r\nnumbOfUnits = 176\r\n# Using If Else statements we check the conditions and calculate the cost per unit.\r\n# If the number of units used equals 100, the cost per unit is Rs 3.46.\r\nif numbOfUnits <= 100:\r\n totalbill = numbOfUnits * 3.46\r\n# If the number of units used is greater than 101 and less than 300,\r\n# the cost per unit is Rs 7.43.\r\nelif numbOfUnits >= 101 and numbOfUnits <= 300:\r\n totalbill = 346 + ((numbOfUnits - 100) * 7.43)\r\n# If you consume more than 301 units and less than 500 units,\r\n# the cost per unit is Rs 10.32.\r\nelif numbOfUnits >= 301 and numbOfUnits <= 500:\r\n totalbill = 346 + 1486 + ((numbOfUnits - 300) * 10.32)\r\n# If the number of units consumed exceeds 501,\r\n# the cost per unit is Rs 11.71.\r\nelse:\r\n totalbill = 346 + 1486 + 2064 + ((numbOfUnits - 500) * 11.71)\r\n# After Calculating cost per unit we multiply the number of units by 1.45 and\r\n# add it to the bill(Adding monthly line rent to the bill)\r\ntotalbill = totalbill + (numbOfUnits*1.45)\r\n# We add Rs 100 to the bill as additional fixed meter rent.\r\ntotalbill = totalbill + 100\r\n# We multiply the present bill amount by 0.16 (Adding the tax) and add this bill to the past bill.\r\ntotalbill = totalbill + (totalbill*0.16)\r\n# Print the Final Electricity Bill.\r\nprint(\"The Electricity bill for the units\", numbOfUnits, '=', totalbill)\r\n<\/pre>\n
The Electricity bill for the units 176 = 1468.4207999999999<\/pre>\n
Method #2:Using If\u00a0 Else Statement (User Input)<\/h3>\n
\n
# Give the number of units consumed as static input and store it in a variable.\r\nnumbOfUnits = int(input('Enter some random number of units ='))\r\n# Using If Else statements we check the conditions and calculate the cost per unit.\r\n# If the number of units used equals 100, the cost per unit is Rs 3.46.\r\nif numbOfUnits <= 100:\r\n totalbill = numbOfUnits * 3.46\r\n# If the number of units used is greater than 101 and less than 300,\r\n# the cost per unit is Rs 7.43.\r\nelif numbOfUnits >= 101 and numbOfUnits <= 300:\r\n totalbill = 346 + ((numbOfUnits - 100) * 7.43)\r\n# If you consume more than 301 units and less than 500 units,\r\n# the cost per unit is Rs 10.32.\r\nelif numbOfUnits >= 301 and numbOfUnits <= 500:\r\n totalbill = 346 + 1486 + ((numbOfUnits - 300) * 10.32)\r\n# If the number of units consumed exceeds 501,\r\n# the cost per unit is Rs 11.71.\r\nelse:\r\n totalbill = 346 + 1486 + 2064 + ((numbOfUnits - 500) * 11.71)\r\n# After Calculating cost per unit we multiply the number of units by 1.45 and\r\n# add it to the bill(Adding monthly line rent to the bill)\r\ntotalbill = totalbill + (numbOfUnits*1.45)\r\n# We add Rs 100 to the bill as additional fixed meter rent.\r\ntotalbill = totalbill + 100\r\n# We multiply the present bill amount by 0.16 (Adding the tax) and add this bill to the past bill.\r\ntotalbill = totalbill + (totalbill*0.16)\r\n# Print the Final Electricity Bill.\r\nprint(\"The Electricity bill for the units\", numbOfUnits, '=', totalbill)\r\n<\/pre>\n
Enter some random number of units =259\r\nThe Electricity bill for the units 259 = 2323.3871999999997<\/pre>\n
\n