Write a Python script to calculate a home’s electricity costs over a number of days.
Thu, 6 Feb 2025 18:00 |
Write a Python script to calculate a home’s electricity costs over a number of days.
Tip
|
Update: I’ve added a footnote to clarify that your code should assume the home in question has a 200A service. |
According to p21 of Newfoundland Power’s Schedule of Rates, Rules & Regulations , an electricity bill for a typical home consists of two parts:
-
a monthly charge of $15.79/mo (if your electrical service does not not [1] exceed 200A) or $20.79/mo (if your service does exceed 200A), and
-
a usage cost of 14.237¢/kWh (which, if you prefer SI units like a sensible person, is 3.9547¢/MJ).
Details
You will submit a Python script (named exactly electricity.py
) that will
input the following details for a typical home [2]
from a user in the following order:
-
daily energy usage
-
for each day, the user should input one number: energy usage in kWh
-
if the user enters an empty string, stop asking for new energy readings
-
otherwise, you may assume that the user enters a valid number
-
-
a starting month
-
you should expect the full, correctly-spelled month name
-
if the month is not valid, prompt the user to try again until they enter a valid month
-
-
a starting day
-
this should be an integer between 1 and 31 (or less, for some months)
-
if the day is not valid, prompt the user to try again until they enter a valid day
-
When complete, your script should output exactly the string
Total cost:
followed by a space and then the cost prefixed with a dollar sign, e.g.,
Total cost: $100.15
.
A bonus mark will be awarded if your output always includes two digits after the
decimal, e.g., $100.00
.
Suggestions / reminders
I would suggest that you start by solving part of or a simplified version of the problem. For example, write a script that calculates energy prices for a number of days but ignores all considerations of months. Then, once you’ve mastered that part of the work, move on to tackle more and more of the assignment. Remember, there is partial credit for partial work, but even more importantly, solving a piece of the problem at a time helps you solve it with confidence.
Remember, assignments are individual work: you must complete the assignment yourself.