L1=[0,260] L2=[0.65,0.7,0.9] d1={1:120,2:105,3:98,4:96,5:90,6:108,7:150,8:150,9:95,10:90,11:92,12:108} v=int(input("请输入第3档的起步电量(整数):")) ###每空3分,int L1.append(v) sum,fee=0,0 for i in d1.keys(): ###d1.keys() sum+=d1[i] ###d1[i] print("累计这一年的用电量为:",sum) if sum>L1[2]: fee1=(L1[1]-L1[0])*L2[0] fee2=(L1[2]-L1[1])*L2[1] fee3=(sum-L1[2])*L2[2] fee=fee1+fee2+fee3 elif sum>L1[1]: ###sum>L1[1] fee1=(L1[1]-L1[0])*L2[0] fee2=(sum-L1[1])*L2[1] fee=fee1+fee2 else: fee=(sum-L1[0])*L2[0] ###L2[0] print("用户这一年需交电费为:%.2f元"%fee)