8-4 文件编程7-4

知识点

按行取数据

代码:

f=open("F:\\vsnode\\python\\water.txt","r+",encoding='utf-8')
while True:
    line=f.readline()
    if not line :break
    line_list=list(line.split())
    if(len(line_list)==0): continue
    print("账户号为",line_list[0],end=" ")
    nums=0.0
    for i in range(1,len(line_list)):
        nums+=int(line_list[i])
    print("的用户,一年的水费为:",nums*1.05)
f.close()

posted @ 2022-06-04 17:13  kingwzun  阅读(40)  评论(0编辑  收藏  举报