标签:join with def count str avg port for adc
save.py
def savetofile(memberlist, avgfee):
with open(‘record.txt‘,‘a‘,encoding=‘utf8‘) as f:
recordlist = [f‘{member}:{avgfee}‘ for member in memberlist]
f.write(‘ | ‘.join(recordlist)+‘\n‘)
aa.py
from save import savetofile
fee = input(‘请输入午餐费用:‘)
members = input(‘请输入聚餐人姓名,以英文逗号,分隔:‘)
# 将人员放入一个列表
memberlist = members.split(‘,‘)
# 得到人数
headcount = len(memberlist)
# 计算人均费用
avgfee = int(fee)/headcount
print(avgfee)
savetofile(memberlist,avgfee)
主要是里面含有循环的嵌套
标签:join with def count str avg port for adc
原文地址:https://www.cnblogs.com/xiajiling1990/p/14849599.html