Skip to content

Instantly share code, notes, and snippets.

@roflsunriz
Last active January 12, 2025 00:34
Show Gist options
  • Save roflsunriz/2c38636bae9fa62476dd4cbc7aa21d2c to your computer and use it in GitHub Desktop.
Save roflsunriz/2c38636bae9fa62476dd4cbc7aa21d2c to your computer and use it in GitHub Desktop.
HeatingCostCalculator : 暖房費計算プログラム 全国の暖房費を暖房器具ごとに1ヶ月のランニングコストを計算します。
class HeatingCostCalculator:
def __init__(self):
# 電力会社ごとの料金データを更新
self.electricity_companies = {
'東京電力': {
'base_fee': 935.25,
'rates': [
{'limit': 120, 'rate': 29.80},
{'limit': 300, 'rate': 36.40},
{'limit': float('inf'), 'rate': 40.49}
]
},
'九州電力': {
'base_fee': 948.72,
'rates': [
{'limit': 120, 'rate': 18.37},
{'limit': 300, 'rate': 23.97},
{'limit': float('inf'), 'rate': 26.97}
]
},
'関西電力': {
'base_fee': 0,
'rates': [
{'limit': float('inf'), 'rate': 22.48}
]
},
'中部電力': {
'base_fee': 990.00,
'rates': [
{'limit': 120, 'rate': 21.04},
{'limit': 300, 'rate': 25.78},
{'limit': float('inf'), 'rate': 28.29}
]
},
'東北電力': {
'base_fee': 990.00,
'rates': [
{'limit': 120, 'rate': 20.32},
{'limit': 300, 'rate': 25.80},
{'limit': float('inf'), 'rate': 29.29}
]
},
'北海道電力': {
'base_fee': 1045.00,
'rates': [
{'limit': 120, 'rate': 22.32},
{'limit': 280, 'rate': 28.30},
{'limit': float('inf'), 'rate': 32.30}
]
},
'中国電力': {
'base_fee': 990.00,
'rates': [
{'limit': 120, 'rate': 19.66},
{'limit': 300, 'rate': 25.15},
{'limit': float('inf'), 'rate': 28.52}
]
},
'四国電力': {
'base_fee': 990.00,
'rates': [
{'limit': 120, 'rate': 20.32},
{'limit': 300, 'rate': 25.80},
{'limit': float('inf'), 'rate': 29.29}
]
},
'北陸電力': {
'base_fee': 990.00,
'rates': [
{'limit': 120, 'rate': 17.46},
{'limit': 300, 'rate': 22.94},
{'limit': float('inf'), 'rate': 26.31}
]
}
}
# ガス会社ごとの料金データ
self.gas_companies = {
'東京ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'大阪ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'東邦ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'西部ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'北海道ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'静岡ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'東彩ガス': {
'base_fee': 759.00,
'rate': 145.31
},
'京葉ガス': {
'base_fee': 759.00,
'rate': 145.31
}
}
# 地域ごとの灯油料金データ
self.kerosene_regions = {
'北海道': {
'rate': 2154.7 / 18 # 1Lあたりの価格に変換
},
'東北': {
'rate': sum([2025.8, 2027.5, 2077.8, 2104.2, 2043.7, 2099.2]) / (6 * 18) # 青森、岩手、宮城、秋田、山形、福島の平均
},
'関東': {
'rate': sum([2034.9, 2070.1, 2103.3, 2155.9, 2179.1, 2122.6, 2135.9]) / (7 * 18) # 茨城、埼玉、千葉、東京、神奈川、栃木、群馬の平均
},
'中部': {
'rate': sum([2054.3, 2082.5, 2111.8, 2121.1, 2097.0, 2057.4, 2085.0, 2098.7, 2105.3]) / (9 * 18) # 山梨、岐阜、愛知、静岡、長野、富山、石川、新潟、福井の平均
},
'関西': {
'rate': sum([2054.3, 2104.5, 2131.0, 1966.7, 2032.0, 2123.3]) / (6 * 18) # 兵庫、大阪、京都、和歌山、奈良、滋賀の平均
},
'中国': {
'rate': sum([2117.3, 2127.9, 2175.4, 2221.2, 2097.4]) / (5 * 18) # 岡山、広島、島根、鳥取、山口の平均
},
'四国': {
'rate': sum([2038.5, 2131.4, 2200.3]) / (3 * 18) # 香川、徳島、愛媛の平均
},
'九州': {
'rate': sum([2003.5, 2033.4, 2052.5, 2078.4, 2048.6, 2125.7, 2195.6]) / (7 * 18) # 熊本、福岡、佐賀、長崎、大分、宮崎、鹿児島の平均
}
}
# デフォルトの料金設定
self.gas_rate = None
self.kerosene_rate = None
# 暖房器具の仕様データ
self.heaters = {
'エアコン': {'type': 'electric', 'power': 1.0, 'efficiency': 3.5},
'電気ヒーター(セラミック/ハロゲン/カーボン)': {'type': 'electric', 'power': 1.0, 'efficiency': 1.0},
'電気ヒーター(オイル/パネル)': {'type': 'electric', 'power': 1.2, 'efficiency': 1.0},
'石油ヒーター': {'type': 'kerosene', 'consumption': 0.2, 'efficiency': 0.9},
'ガスヒーター': {'type': 'gas', 'consumption': 0.15, 'efficiency': 0.85}
}
def calculate_electricity_cost(self, kwh_usage):
if not hasattr(self, 'selected_company'):
raise ValueError("電力会社が設定されていないのじゃ!")
company_data = self.electricity_companies[self.selected_company]
total_cost = company_data['base_fee'] # 基本料金
remaining_kwh = kwh_usage
# 段階別料金の計算
for i, rate_info in enumerate(company_data['rates']):
if remaining_kwh <= 0:
break
usage_in_stage = min(remaining_kwh, rate_info['limit'])
if i > 0: # 2段階目以降の場合
usage_in_stage = min(remaining_kwh,
rate_info['limit'] - company_data['rates'][i-1]['limit'])
cost_in_stage = usage_in_stage * rate_info['rate']
total_cost += cost_in_stage
remaining_kwh -= usage_in_stage
return round(total_cost)
def calculate_monthly_cost(self, heater_name, hours_per_day=16, days_per_month=30):
if not all([hasattr(self, 'selected_company'), self.gas_rate, self.kerosene_rate]):
raise ValueError("エネルギー料金が設定されていないのじゃ!")
heater = self.heaters[heater_name]
monthly_hours = hours_per_day * days_per_month
if heater['type'] == 'electric':
power_consumption = heater['power'] / heater['efficiency'] # 実際の消費電力
monthly_kwh = power_consumption * monthly_hours
cost = self.calculate_electricity_cost(monthly_kwh)
elif heater['type'] == 'kerosene':
consumption = heater['consumption'] / heater['efficiency']
cost = consumption * self.kerosene_rate * monthly_hours
elif heater['type'] == 'gas':
consumption = heater['consumption'] / heater['efficiency']
cost = consumption * self.gas_rate * monthly_hours
return round(cost)
def set_electricity_company(self, company_name):
if company_name in self.electricity_companies:
self.selected_company = company_name
return True
return False
def set_gas_company(self, company_name):
if company_name in self.gas_companies:
self.gas_rate = self.gas_companies[company_name]['rate']
return True
return False
def set_kerosene_region(self, region_name):
if region_name in self.kerosene_regions:
self.kerosene_rate = self.kerosene_regions[region_name]['rate']
return True
return False
def get_available_heaters(self):
return list(self.heaters.keys())
def calculate_selected_heaters(self, selected_heaters, hours_per_day=16, days_per_month=30):
results = {}
for heater in selected_heaters:
if heater in self.heaters:
cost = self.calculate_monthly_cost(heater, hours_per_day, days_per_month)
results[heater] = cost
return results
def calculate_gas_cost(self, gas_usage):
if not self.gas_rate:
raise ValueError("ガス会社が設定されていないのじゃ!")
company_data = self.gas_companies[self.selected_gas_company]
total_cost = company_data['base_fee'] + (gas_usage * company_data['rate'])
return round(total_cost)
def main():
print("暖房費計算プログラムへようこそなのじゃ!٩(。•ω•。)و\n")
calculator = HeatingCostCalculator()
# 地域選択
print("=== お住まいの地域を選んでください ===")
regions = {
'1': {'area': '北海道', 'electric': '北海道電力', 'gas': '北海道ガス', 'kerosene': '北海道'},
'2': {'area': '東北', 'electric': '東北電力', 'gas': '東邦ガス', 'kerosene': '東北'},
'3': {'area': '関東', 'electric': '東京電力', 'gas': '東京ガス', 'kerosene': '関東'},
'4': {'area': '中部', 'electric': '中部電力', 'gas': '東邦ガス', 'kerosene': '中部'},
'5': {'area': '関西', 'electric': '関西電力', 'gas': '大阪ガス', 'kerosene': '関西'},
'6': {'area': '中国', 'electric': '中国電力', 'gas': '西部ガス', 'kerosene': '中国'},
'7': {'area': '四国', 'electric': '四国電力', 'gas': '西部ガス', 'kerosene': '四国'},
'8': {'area': '九州', 'electric': '九州電力', 'gas': '西部ガス', 'kerosene': '九州'}
}
for key, value in regions.items():
print(f"{key}: {value['area']}")
while True:
region_choice = input("\n番号を入力してください: ")
if region_choice in regions:
selected_region = regions[region_choice]
break
print("正しい番号を入力するのじゃ!")
# 電力・ガス・灯油の料金設定
calculator.set_electricity_company(selected_region['electric'])
calculator.set_gas_company(selected_region['gas'])
calculator.set_kerosene_region(selected_region['kerosene'])
# 暖房器具選択
print("\n=== 比較したい暖房器具を選んでください ===")
heaters = calculator.get_available_heaters()
for i, heater in enumerate(heaters, 1):
print(f"{i}: {heater}")
selected_heaters = []
while True:
print("\n暖房器具の番号を入力してください(複数選択可能、完了したらEnterキーを押してください)")
choice = input("番号: ")
if choice == "":
if selected_heaters:
break
print("少なくとも1つは選ぶのじゃ!")
continue
try:
index = int(choice) - 1
if 0 <= index < len(heaters):
if heaters[index] not in selected_heaters:
selected_heaters.append(heaters[index])
print(f"「{heaters[index]}」を追加したのじゃ!")
else:
print("その暖房器具は既に選択済みなのじゃ!")
else:
print("正しい番号を入力するのじゃ!")
except ValueError:
print("数字を入力するのじゃ!")
# 使用時間の設定
print("\n=== 1日の使用時間を入力してください ===")
while True:
try:
hours = float(input("時間(デフォルト: 16時間): ") or "16")
if 0 < hours <= 24:
break
print("0より大きく24以下の数値を入力するのじゃ!")
except ValueError:
print("正しい数値を入力するのじゃ!")
# 計算と結果表示
print("\n=== 計算結果 ===")
print(f"地域: {selected_region['area']}")
print(f"1日の使用時間: {hours}時間")
print("\n月間のランニングコスト:")
results = calculator.calculate_selected_heaters(selected_heaters, hours_per_day=hours)
# コストが低い順にソート
sorted_results = sorted(results.items(), key=lambda x: x[1])
for heater, cost in sorted_results:
print(f"・{heater}: {cost:,}円")
print("\n※ この計算結果は目安です。実際の使用状況や気候条件によって変動する可能性があるのじゃ!")
print("体調管理のために、適度な室温を保つことを忘れないでほしいのじゃ!(`・ω・´)ゞ")
input("Enterキーを押して終了するのじゃ!")
if __name__ == "__main__":
main()
@roflsunriz
Copy link
Author

使い方:
1.プログラムを起動する。
2.地域を選ぶ。
3.比較したい暖房器具を選ぶ。(複数選択可)
4.1日の使用時間を入力する。(デフォルト:16時間)
5.計算結果を見る。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment