zoukankan      html  css  js  c++  java
  • python day08作业答案

    1.
    a
    f=open('11.txt','r',encoding='utf-8')
    a=f.read()
    print(a)
    f.flush()
    f.close()
    b.
    f=open('11.txt','a',encoding='utf-8')
    f.write('信不信由你')
    f.flush()
    f.close()
    c.
    f=open('11.txt','r+',encoding='utf-8')
    a=f.read()
    print(a)
    f.write('信不信由你')
    f.flush()
    f.close()
    d.
    f=open('11.txt','w',encoding='utf-8')
    f.write('每天坚持一点')
    f.flush()
    f.close()
    e.
    f1=open('11.txt','r',encoding='utf-8')
    f2=open('11.1','w',encoding='utf-8')
    a=f1.readline()
    b=f1.readline()
    c=f1.readline()
    d=f1.readline()
    f2.write(a)
    f2.write(b)
    f2.write(c)
    f2.write('你们就信了吧。')
    f2.write(d)
    
    2.
    a,b
    with open('t1.txt','r+',encoding='utf-8') as f1:
        a=f1.read()
        f1.write('a')
    for line in a:
        print(line)
    c.
    with open('t1.txt','r',encoding='utf-8') as f1:
        a=f1.readlines()
    for line in a:
        print(line)
    d.
    with open('t1.txt','r',encoding='utf-8') as f1:
        a=f1.read(4)
    print(a)
    
    e.
    with open('t1.txt','r',encoding='utf-8') as f1:
        a=f1.readline()
        a.replace(' ','')
        a.replace('/n','')
    print(a)
    f.
    with open('t1.txt','r',encoding='utf-8') as f1:
        a=f1.readline()
        b=f1.readline()
        c=f1.readline()
    print(c)
    
    
    g.
    with open('t1.txt','a+',encoding='utf-8') as f1:
    
        f1.write('老男孩教育')
        f1.seek(0)
        a=f1.read()
        print(a)
    
    
    h.
    with open('t1.txt','r',encoding='utf-8') as f1:
        a = f1.read()
    print(a)
    3.
    b=[]
    with open('a.txt','r',encoding='utf-8') as f1:
        df=f1.readlines()
    for i in  range(0,len(df)):
        a = {}
        a['name']=df[i].replace('
    ','').split(' ')[0]
        a['price'] = df[i].replace('
    ','').split(' ')[1]
        a['amount'] = df[i].replace('
    ','').split(' ')[2]
        b.append(a)
    print(b)
    
    4.
    f1= open('4.txt','r',encoding='utf-8')
    f2=open('4.1.txt','w+',encoding='utf-8')
    a=f1.read()
    c=a.replace('alex','SB')
    f2.write(c)
    5.
    lst=[]
    f1= open('a.txt','r',encoding='utf-8')
    for i in f1:
        lst1=i.split()
        print(lst1)
        dic={}
        dic[lst1[0].split(':')[0]]=lst1[0].split(':')[1]
        dic[lst1[1].split(':')[0]]=lst1[1].split(':')[1]
        dic[lst1[2].split(':')[0]] =lst1[2].split(':')[1]
        dic[lst1[3].split(':')[0]] = lst1[3].split(':')[1]
        lst.append(dic)
    print(lst)
    6.
    lst=[]
    f1= open('a.txt','r',encoding='utf-8')
    a=f1.readline().split()
    print(a)
    for i in f1:
        dic={}
        print(i)
        dic[a[0]]=i.split()[0]
        dic[a[1]]=i.split()[1]
        dic[a[2]]=i.split()[2]
        lst.append(dic)
    print(lst)
  • 相关阅读:
    iframe自适应高度的多种方法
    jquery 限制上传文件的类型和大小
    20200303 pandas
    20200306 Linux基础
    20200305 VMware虚拟机安装及centOS
    20200310 CMDB基础设计
    20200407 算法与数据结构
    20200403 MongoDB操作以及pyMongo
    20200402 MongoDB安装及简介
    20200401 docker部署与mysql主从搭建django读写分离
  • 原文地址:https://www.cnblogs.com/snackpython/p/9950446.html
Copyright © 2011-2022 走看看