python分时阶梯电价

'''每秒将 时间 及功耗传入;
湖北地区,'''
#totalPower
totalPW=0
#totalMoney
totalMy=0
#分时电量1
def PowerTime(usptime): # 输入时间得到分时系数
    # 分时电价
    '''
    20-22 180%
    9-15 149%
    7-9 100%
    15-20 100%
    22-23 100%
    23-24 48%
    0-7 48%
    '''
    atim,btim,ctim,dtim=[],[],[],[]
    for i in range(20,22):
        atim.append(i)
    for i in range(9,15):
        btim.append(i)
    for i in range(7,9):
        ctim.append(i)
    for i in range(15,21):
        ctim.append(i)
    dtim.append(23)
    for i in range(0,7):
        dtim.append(i)
    if usptime in atim:
        uptime=1.8
        return uptime
    if usptime in btim:
        uptime=1.49
        return uptime
    if usptime in atim:
        uptime=1
        return uptime
    if usptime in dtim:
        uptime=0.48
        return uptime

def CalcuMoney(uspower,uptime): # 输入每秒kwh 全年累计 得到累计及阶梯电价
    # 阶梯电价——年千瓦时
    """
    1.<2160             0.558
    2.2160<=   <=4800   0.608
    3.<4800             0.858
    """
    '''
    #基金及税钱—每千瓦时
    0.0188+0.02+0.0062+0.001=0.046
    '''
    global totalMy
    global totalPW
    totalPW = totalPW + uspower
    if totalPW < 2160:
        usmoney = (0.558*uspower*uptime) + (0.046*uspower)
    elif totalPW < 4800:
        usmoney = 0.608*uspower*uptime + (0.046*uspower)
    else:
        usmoney = 0.858*uspower*uptime + (0.046*uspower)
    totalMy = totalMy + usmoney
    return totalPW, usmoney, totalMy

if __name__ == '__main__':
    #uspower 每秒功耗kwh;usptime 功耗所处小时。
    uspower=1000
    usptime=0
    info=CalcuMoney(uspower, PowerTime(usptime))
    print("累计用电",info[0],"KWH")
    print("实时电费",info[1],"RMB")
    print("累计电费",info[2],"RMB")