Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(PYTHON) Write a program that can calculate the electricalenergy used by an electrical device and its price. The program canidentify several different units of power

(PYTHON) Write a program that can calculate the electricalenergy used by an electrical device and its price. The program canidentify several different units of power (watts, kilowatts andhorsepower) and units of time (minutes, hours and days) and changethe values ??entered by the user to the appropriate units. OneHorsepower is 746 watts or 0.746 kilowatts. Use this value tochange horsepower.

Write the following functions in the program:- calculate_energy (power, power_unit, time, time_unit)The function is to calculate the amount of energy that is transferred / consumed when the power is known (i.e. the energy transfer / consumption rate). The power is assumed to be the same all the time, so the energy is obtained by multiplying the power by time.The function gets the following values ??as parameters in this order:     power: float - a decimal number representing constant power     power_unit: str (string) - the unit where the power is. Either "W", "kW" or "hp"     time: float - a decimal number that describes the time during which energy is transferred at a given constant power     time_unit: str (string) - unit where time is. Either "minutes", "hours" or "days"The function calculates and returns energy in kilowatt hours, unless one of the values ??is incorrectIf any parameter is invalid, the program returns -99. Incorrect means that the unit is not one of the given options or the numeric value is negative. Zero is thus a permissible value, which of course produces a return value of 0.0. A device that is not switched on for a moment or has an input power of 0 W consumes 0.0 kilowatt hours - it is important to take borderline cases into account when programming.Note, then, that this is a fairly general-purpose function that can calculate anything that is transmitted at constant power, that is, electrical energy other than that used by devices (albeit only in kilowatt hours), although here we only use this to calculate electrical energy.- calculate_energy_cost (energy_kwh, price_per_kwh)The function takes the amount of electrical energy (kWh) and the unit price of electricity (? / kWh) as parameters. The function returns the total cost of electricity in euros.
In addition, write a main program that communicates with the user according to the examples given, asks for appropriate values, and prints the results. Only the main program must communicate directly with the user, ie all print and input commands must be in the main program. The main program queries the unit of power, power, unit of time, and time in that order, and then calls the calculate_energy function. If the return value was -99, that is, one or more of the values ??were invalid, the program prints You have entered some invalid values. and cease operations. Otherwise, the program still asks for the price of electricity and prints the total cost according to the examples.
It is recommended that you copy the following Standards to the beginning of your program, outside the functions, and refer to them whenever necessary, for example, instead of typing in multiple fields -99:
HORSEPOWER_IN_KW = 0.746ERROR_WITH_CALCULATE_ENERGY = -99
Examples of main program execution:

image

image

image

image

image

Welcome to calculate the energy used by the appliance and its cost! What unit to use for the power ('W', 'kW' or 'hp')? W Enter the power of the appliance in W: 12.3 What unit to use for the time ('minutes', 'hours' or 'days')? days Enter the time the appliance is running in days: 30 You have an appliance of 12.3 W running for 30.0 days. It consumes approximately 8.86 kwh. Enter the electricity price in cents / kWh: 11.8 The energy will cost approximately 1.05 eur.

Step by Step Solution

3.52 Rating (169 Votes )

There are 3 Steps involved in it

Step: 1

HORSEPOWERINKW 0746 ERRORWITHCALCULATEENERGY 99 def calculateenergypower powerunit time timeunit if ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modeling the Dynamics of Life Calculus and Probability for Life Scientists

Authors: Frederick R. Adler

3rd edition

840064187, 978-1285225975, 128522597X, 978-0840064189

More Books

Students also viewed these Programming questions