zoukankan      html  css  js  c++  java
  • 3.17作业

    1、编写文件修改功能,调用函数时,传入三个参数(修改的文件路径,要修改的内容,修改后的内容)既可完成文件的修改

    def x(a,b,c):
        import os
        with open('{}'.format(a), mode='rt', encoding='utf-8') as f, 
                open('b.txt', mode='wt', encoding='utf-8') as f1:
            for line in f:
                f1.write(line.replace(b, c))
    
        os.remove('a.txt')
        os.rename('b.txt', 'a.txt')
    
    
    x('a.txt','egon','oldboy')
    

    2、编写tail工具
    用来写内容

    def write():
        while 1:
            cmd=input('请输入要写的内容(q退出):').strip()
            if cmd == 'q':
                break
            with open(r'a.txt',mode='ab') as f:       #a.txt可以自定义为任意文件
                f.write(f'{cmd}
    '.encode('utf-8'))
    
    
    write()
    

    监控

    def tail_too():
        import time
        with open('a.txt', mode='rb') as f:
            f.seek(0, 2)
            while True:
                line = f.readline()
                if len(line) == 0:
                    time.sleep(0.3)
                else:
                    print(line.decode('utf-8'), end='')
    tail_too()
    

    3、编写登录功能

    def d():
        name=input('your name:').strip()
        pwd=input('your pwd:').strip()
        with open(r'users.txt',mode='rt',encoding='utf-8') as f:
            for users in f:
                name1,pwd1=users.strip().split(':')
                if name == name1 and pwd == pwd1:
                    print('login successfully')
                    break
            else:
                print('name or pwd error')
    

    4、编写注册功能

    def z():
        while 1:
            name=input('your name:').strip()
            pwd=input('your pwd:').strip()
            with open(r'users.txt',mode='r+t',encoding='utf-8') as f:
                for i in f:
                    name1,pwd1=i.strip().split(':')
                    if name == name1:
                        print('用户名重复')
                        break
                else:
                    f.write(f'{name}:{pwd}
    ')
                    print('注册成功')
                    break
    

    课后娱乐注册,登录程序(配合3.4使用)

    while 1:
        print('''
        0 退出
        1 注册
        2 登录''')
        cmd=input('请输入命令:').strip()
        if not cmd.isdigit():
            print('请输入纯数字命令,傻子')
        if cmd == '1':
            z()
            break
        if cmd == '2':
            d()
            break
        if cmd == '0':
            print('正在退出程序')
            break
        else:
            print('命令不存在')
    

    选做题:编写ATM程序实现下述功能,数据来源于文件db.txt
    1、充值功能:用户输入充值钱数,db.txt中该账号钱数完成修改
    2、转账功能:用户A向用户B转账1000元,db.txt中完成用户A账号减钱,用户B账号加钱
    3、提现功能:用户输入提现金额,db.txt中该账号钱数减少
    4、查询余额功能:输入账号查询余额

    选做题中的选做题:登录功能
    用户登录成功后,内存中记录下该状态,上述功能以当前登录状态为准,必须先登录才能操作

  • 相关阅读:
    HTML Style Sheet
    Chrome 崩溃 相关
    android dialog 不变暗
    URL replacement
    android SharedPreferences
    android PreferenceActivity
    据说还可以的网站
    android brightness control
    Android network status 3G/WIFI
    android activity onSearchRequested()
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12511450.html
Copyright © 2011-2022 走看看