鱼C论坛

 找回密码
 立即注册
查看: 2817|回复: 5

[已解决]课后作业31讲

[复制链接]
发表于 2023-1-31 16:05:29 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

import pickle

def pickles(file):
    boy = []
    girl = []
    count = 1
    for i in file:
        i = i.replace('\n','')
        words = i.split(':')
        if words[0] == '小甲鱼':
            boy.append(words[1])
        if words[0] == '小客服':
            girl.append(words[1])
        if i[0:7] == '=======':
            pickle_file_boy = open('boy_' + str(count) + '.txt','wb')
            pickle.dump(boy,pickle_file_boy)
            pickle_file_boy.close()
            pickle_file_girl = open('girl_' + str(count) + '.txt','wb')
            pickle.dump(boy,pickle_file_girl)
            pickle_file_girl.close()
            count += 1
            boy.clear()
            girl.clear()
        if words[0] == '小甲鱼':
            boy.append(words[1])
        if words[0] == '小客服':
            girl.append(words[1])
        pickle_file = open('boy_' + str(count) + '.txt','wb')
        pickle.dump(boy,pickle_file)
        pickle_file.close()
        pickle_file = open('girl_' + str(count) + '.txt','wb')
        pickle.dump(boy,pickle_file)
        pickle_file.close()
file_content = open('record.txt','r')
pickles(file_content)

file_name = open('boy_1.txt','rb')
list1 = pickle.load(file_name)
print(list1)


31讲课后作业,为毛打印出来的列表是这样的?
['咦??', '咦??', '。。。。。。', '。。。。。。', '然后呢?', '然后呢?', '呃。。。。。。你真牛!', '呃。。。。。。你真牛!', '下次有人想调戏你我不阻止~', '下次有人想调戏你我不阻止~'],次数变多了两倍?哪个亲爱滴鱼油告我一下,嘿嘿嘿。
最佳答案
2023-2-1 23:17:37
。。进来发现已经改好了,没什么问题的话设个最佳答案呗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-1-31 16:07:09 | 显示全部楼层
sb了,我知道了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-1-31 16:16:22 | 显示全部楼层

重复了两次


import pickle

def pickles(file):
    boy = []
    girl = []
    count = 1
    for i in file:
        i = i.replace('\n','')
        words = i.split(':')
       if words[0] == '小甲鱼':
            boy.append(words[1])
        if words[0] == '小客服':
            girl.append(words[1])

        if i[0:7] == '=======':
            pickle_file_boy = open('boy_' + str(count) + '.txt','wb')
            pickle.dump(boy,pickle_file_boy)
            pickle_file_boy.close()
            pickle_file_girl = open('girl_' + str(count) + '.txt','wb')
            pickle.dump(boy,pickle_file_girl)
            pickle_file_girl.close()
            count += 1
            boy.clear()
            girl.clear()
       if words[0] == '小甲鱼':
            boy.append(words[1])
        if words[0] == '小客服':
            girl.append(words[1])

        pickle_file = open('boy_' + str(count) + '.txt','wb')
        pickle.dump(boy,pickle_file)
        pickle_file.close()
        pickle_file = open('girl_' + str(count) + '.txt','wb')
        pickle.dump(boy,pickle_file)
        pickle_file.close()
file_content = open('record.txt','r')
pickles(file_content)

file_name = open('boy_1.txt','rb')
list1 = pickle.load(file_name)
print(list1)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-1-31 16:19:42 | 显示全部楼层
import pickle

def pickles(file):
    boy = []
    girl = []
    count = 1
    for i in file:
        i = i.replace('\n','')
        words = i.split(':')
        if i[0:7] != '=======':
            if words[0] == '小甲鱼':
                boy.append(words[1])
            if words[0] == '小客服':
                girl.append(words[1])
        else:
            pickle_file_boy = open('boy_' + str(count) + '.txt','wb')
            pickle.dump(boy,pickle_file_boy)
            pickle_file_boy.close()
            pickle_file_girl = open('girl_' + str(count) + '.txt','wb')
            pickle.dump(girl,pickle_file_girl)
            pickle_file_girl.close()
            count += 1
            boy.clear()
            girl.clear()
    pickle_file = open('boy_' + str(count) + '.txt','wb')
    pickle.dump(boy,pickle_file)
    pickle_file.close()
    pickle_file = open('girl_' + str(count) + '.txt','wb')
    pickle.dump(boy,pickle_file)
    pickle_file.close()
   
file_content = open('record.txt','r')
pickles(file_content)

file_name = open('girl_1.txt','rb')
list1 = pickle.load(file_name)
print(list1)

这是改好了的。。。。。。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-2-1 23:17:37 | 显示全部楼层    本楼为最佳答案   
。。进来发现已经改好了,没什么问题的话设个最佳答案呗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-2-2 19:45:04 | 显示全部楼层
hziyan 发表于 2023-2-1 23:17
。。进来发现已经改好了,没什么问题的话设个最佳答案呗

哈哈哈哈哈哈哈,笑死,ok
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-24 19:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表