pta的一道题,关于文件的
用水量文件"water.txt"的第一列为账号,下面是每个月的用水量(后一个数-前一个数),共十二个月。每立方米需付1.05元。编程计算每户一年的水费。@ 。程序压缩后(zip格式)以文件形式上传!0000359333 772 789 806 847 880 901 950 991 1022 1043 1064 1089 1114
0000359305 121 132 145 156 168 179 192 206 219 230 246 258 273
0000359708 1008 1046 1102 1167 1209 1255 1311 1362 1407 1453 1512 1563 1604
0000359504 541 567 590 622 651 689 701 732 758 775 796 814 847
0000359209 401 412 441 466 479 490 508 522 541 572 603 637 666。 f = open('water.txt',encoding='utf-8')
userlst =
for i in range(len(userlst)):
for j in range(len(userlst)):
userlst = int(userlst)
userdict = {}
for i in range(len(userlst)):
usersum = 0
for j in range(len(userlst)):
if j > 1:
new = userlst - userlst
usersum+=new
userdict] = round(usersum*1.05,2)
print(userlst,round(usersum*1.05,2))
本帖最后由 qq1151985918 于 2021-2-2 12:36 编辑
with open("water.txt","r",encoding = "utf-8") as f:
data = f.readlines()
userdata = {}
for each in data:
userlist = each.split()
if userlist:
userdata] = list(map(float,userlist))
for key,value in userdata.items():
num = value[-1] - value
print("用户%s一年的水费为%.2f元"%(key,num * 1.05))
页:
[1]