unitPrice=0.56 #基础电价
eleCharge=0 #每月应缴电费
while(True):
month=int(input("请选择当前的月份(1-12):"))
if month >= 1 and month <= 12:
break
else:
continue
while(True):
sumDegrees=float(input("请输入您当月所使用的用电度数:"))
if sumDegrees >= 0:
break
else:
continue
if monthin[1,2,3,4,11,12]: # 如果当前是非夏季
if sumDegrees <= 200:
eleCharge = unitPrice * sumDegrees
elif sumDegrees > 200 and sumDegrees<= 400:
d1 = 200 * unitPrice
d2 = (sumDegrees - 200) * (unitPrice +0.08)
eleCharge = d1 + d2
else:
d1 = 200 * unitPrice
d2 = 200 * (unitPrice + 0.08)
d3 = (sumDegrees - 400) * (unitPrice +0.5)
eleCharge = d1 + d2 + d3
else: # 如果当前是夏季
if sumDegrees <= 200:
eleCharge = unitPrice * sumDegrees
elif sumDegrees > 200 and sumDegrees<= 500:
d1 = 200 * unitPrice
d2 = (sumDegrees - 200) * (unitPrice +0.05)
eleCharge = d1 + d2
else:
d1 = 200 * unitPrice
d2 = 300 * (unitPrice + 0.05)
d3 = (sumDegrees - 500) * (unitPrice +0.3)
eleCharge = d1 + d2 + d3
print("您%d月所使用电量的电费为%.2lf元"%(month,eleCharge))