Skip to content

Instantly share code, notes, and snippets.

@fiskr
Last active August 27, 2015 11:08
Show Gist options
  • Save fiskr/25e73467ec77d2626f75 to your computer and use it in GitHub Desktop.
Save fiskr/25e73467ec77d2626f75 to your computer and use it in GitHub Desktop.
Script to compare lightbulb costs
# Author: Brandon Foster
# Date: 20150826
# Purpose:
# - automate the comparisons between lightbulbs
# INC stands for Incandescent
# LED stands for Light-emitting diode
# CFL stands for Compact Fluorescents
class LightBulb:
def __init__(self):
self.cost = 0
self.watts = 0
self.longevity = 0
self.hoursUsed = 0
self.replacements = 0
led = LightBulb()
led.cost = 8
led.watts = 8
led.longevity = 50000
inc = LightBulb()
inc.cost = 1
inc.watts = 60
inc.longevity = 1200
cfl = LightBulb()
cfl.cost = 6
cfl.watts = 15
cfl.longevity = 8000
HOURS_USED_PER_YEAR = 1142
COST_PER_KILOWATT_HOURS = 0.08826 # in dollars
def calcTotalCost(bulb, years):
totalCost = 0
# what it costs to run the bulb for however many years
maintenanceCost = (bulb.watts * (COST_PER_KILOWATT_HOURS / 1000)) * (HOURS_USED_PER_YEAR * years)
totalCost += maintenanceCost
totalCost += bulb.cost
bulb.hoursUsed += (HOURS_USED_PER_YEAR * years)
def replaceBulbs(bulb, totalCost):
if bulb.hoursUsed >= bulb.longevity:
bulb.replacements += 1
bulb.hoursUsed -= bulb.longevity
totalCost += bulb.cost
replaceBulbs(bulb, totalCost)
else:
pass
replaceBulbs(bulb, totalCost)
return totalCost
YEARS_TO_CHECK = 10
YEARS_CHECKED = 0
while YEARS_CHECKED < YEARS_TO_CHECK:
YEARS_CHECKED += 1
print
print
print '$' + str(calcTotalCost(led, YEARS_CHECKED)) + ' to operate LED for ' + str(YEARS_CHECKED) + ' years, requiring ' + str(led.replacements) + ' replacements.'
print '$' + str(calcTotalCost(inc, YEARS_CHECKED)) + ' to operate INC for ' + str(YEARS_CHECKED) + ' years, requiring ' + str(inc.replacements) + ' replacements.'
print '$' + str(calcTotalCost(cfl, YEARS_CHECKED)) + ' to operate CFL for ' + str(YEARS_CHECKED) + ' years, requiring ' + str(cfl.replacements) + ' replacements.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment