3/25 本周选做题

def auth(path):
    from functools import wraps
    global money

    def outter1(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            import time
            time1 = time.strftime(‘%Y-%m-%d %X‘)
            func()
            print(func.__name__, type(func.__name__))
            with open(r‘{}‘.format(path), ‘a‘, encoding=‘utf-8‘) as f:
                if func.__name__ == ‘money_in‘:
                    f.write(‘{} {} 充值 {}\n‘.format(time1, user_in, money))
                if func.__name__ == ‘money_out‘:
                    f.write(‘{} {} 消费 {} 元\n‘.format(time1, user_in, money))

        return wrapper

    return outter1

def log_in():
    import os, time
    global login
    global user_in
    while True:
        user = input(‘请输入账号:‘).strip()
        if os.path.exists(‘{}‘.format(user)):
            with open(‘{}‘.format(user), ‘r‘, encoding=‘utf-8‘) as f:
                l = f.read()
            if float(l) > time.time():
                print(‘该用户被锁定了‘)
                continue
            else:
                os.remove(‘{}‘.format(user))
        with open(‘db.txt‘, ‘r‘, encoding=‘utf-8‘) as f5:
            for line in f5:
                user1, pwd1, money1 = line.strip().split(‘:‘)
                if user == user1:
                    count = 0
                    while count < 3:
                        pwd = input(‘请输入密码:‘).strip()
                        if pwd == pwd1:
                            login = True
                            user_in = user
                            print(‘登陆成功‘)
                            return 1
                        else:
                            count += 1
                            print(‘登录失败‘)
                    with open(‘{}‘.format(user), ‘w‘, encoding=‘utf-8‘) as f:
                        f.write(str(time.time() + 300))
                    print(‘该用户已经被锁定了,傻叉‘)
                    login = False
                    return login
            else:
                print(‘没有这个用户哦‘)

def outter(func):
    from functools import wraps
    @wraps(func)
    def wrapper(*args, **kwargs):
        while True:
            if login:
                func()
                break
            else:
                print(‘请登录后操作‘)
                log_in()

    return wrapper

def register():
    tag = True
    while tag:
        tag1 = True
        user = input(‘请输入账号:‘).strip()
        if user:
            with open(‘db.txt‘, ‘r‘, encoding=‘utf-8‘) as f:
                for i in f:
                    i, *_ = i.strip().split(‘:‘)
                    if i == user:
                        tag1 = False
                        print(‘该用户已存在...‘)
                        break
            if tag1:
                pwd = input(‘请输入密码:‘).strip()
                pwd1 = input(‘请再次输入确认密码:‘).strip()
                if pwd:
                    if pwd == pwd1:
                        while tag:
                            money = input(‘请输入你要存的金额:‘).strip()
                            if money.isdigit():
                                with open(‘db.txt‘, ‘a‘, encoding=‘utf-8‘) as f5:
                                    f5.write(‘{}:{}:{}\n‘.format(user, pwd, money))
                                print(‘注册成功‘)
                                tag = False
                            else:
                                print(‘金额输入有误,请输入整数‘)
                    else:
                        print(‘密码不一致‘)
                else:
                    print(‘密码不能为空哦‘)
        else:
            print(‘账号不能为空哦‘)

@auth(‘daliy.txt‘)
@outter
def money_in():
    while True:
        money = input(‘请输入充值金额:‘).strip()
        if money.isdigit():
            with open(‘db.txt‘, ‘r‘, encoding=‘utf-8‘) as f,                     open(‘.db.txt.swap‘, ‘w‘, encoding=‘utf-8‘) as f1:
                for line in f:
                    user1, pwd1, money1 = line.strip().split(‘:‘)
                    if user_in == user1:
                        money1 = int(money1)
                        money1 += int(money)
                    f1.write(‘{}:{}:{}\n‘.format(user1, pwd1, money1))
                print(‘充值成功,充值金额为:{}‘.format(money))

        else:
            print(‘请输入整数数字‘)
            continue
        os.remove(‘db.txt‘)
        os.rename(‘.db.txt.swap‘, ‘db.txt‘)
        return 1

@auth(‘daliy.txt‘)
@outter
def money_out():
    global money
    while True:
        if str(money).isdigit():
            with open(‘db.txt‘, ‘r‘, encoding=‘utf-8‘) as f,                     open(‘.db.txt.swap‘, ‘w‘, encoding=‘utf-8‘) as f2:
                for i in f:
                    user1, pwd1, money1 = i.strip().split(‘:‘)
                    if user1 == user_in:
                        money1 = int(money1)
                        money = int(money)
                        if money < money1:
                            money1 -= money
                            print(‘购买成功,金额为:{}‘.format(money))
                        else:
                            print(‘没那么多钱‘)
                    f2.write(‘{}:{}:{}\n‘.format(user1, pwd1, money1))
            os.remove(‘db.txt‘)
            os.rename(‘.db.txt.swap‘, ‘db.txt‘)
            return 1
        else:
            print(‘请输入整数数字,傻叉‘)

@outter
def readbook1():
    global money
    while True:
        print(‘‘‘--------------------------------
    0 玄幻武侠
    1 都市爱情
    2 高效养猪36技
--------------------------------    ‘‘‘)
        with open(‘story_class.txt‘, ‘r‘, encoding=‘utf-8‘) as f:
            d = eval(f.read())
        choice1 = input(‘请输入命令编号:‘).strip()
        if choice1.isdigit():
            if choice1 in d:
                while True:
                    for key1, value1 in d[choice1].items():
                        print(‘{} {} 价格:{}‘.format(key1, value1[0], value1[1]))
                    choice2 = input(‘请输入命令编号:‘).strip()
                    if choice2.isdigit():
                        if choice2 in d[choice1]:
                            print(‘--------------------------------‘)
                            choice3 = input(‘是否付费:‘).strip()
                            print(‘--------------------------------‘)
                            if choice3.upper() == ‘Y‘:
                                money = d[choice1][choice2][1]
                                money_out()
                            break
                        print(‘no book‘)
                    else:
                        print(‘请输入整数数字‘)
            else:
                print(‘no book‘)
        else:
            print(‘请输入整数数字‘)

if __name__ == ‘__main__‘:
    import os, time

    money = 0
    use_in = None
    login = False
    dic = {‘0‘: register, ‘1‘: money_in, ‘2‘: readbook1}
    while True:
        print(‘‘‘--------------------------------
        0 账号注册
        1 充值功能
        2 阅读小说
--------------------------------        ‘‘‘)
        choice = input(‘请输入命令编号:‘).strip()
        if choice.isdigit():
            if choice in [‘1‘, ‘2‘, ‘3‘]:
                dic[choice]()
            else:
                print(‘没有这个编号,傻叉‘)
        else:
            print(‘请输入整数数字‘)

原文地址:https://www.cnblogs.com/pythonwl/p/12569293.html

时间: 2024-08-30 13:58:22

3/25 本周选做题的相关文章

课后选做题-MyOD

课后选做题-MyOD od命令的了解 功能 od命令用于将指定文件内容以八进制.十进制.十六进制.浮点格式或ASCII编码字符方式显示,通常用于显示或查看文件中不能直接显示在终端的字符.od命令系统默认的显示方式是八进制,名称源于Octal Dump. 常见的文件为文本文件和二进制文件.od命令主要用来查看保存在二进制文件中的值,按照指定格式解释文件中的数据并输出,不管是IEEE754格式的浮点数还是ASCII码,od命令都能按照需求输出它们的值. 语法 od 参数 -a 此参数的效果和同时指定

18.5.12 c++选做题#4

4:自己实现bitset 描述程序 填空,实现一个类似STL bitset的 MyBitset, 输出指定结果 #include <iostream> #include <cstring> using namespace std; template <int bitNum> struct MyBitset { char a[bitNum/8+1]; MyBitset() { memset(a,0,sizeof(a));}; void Set(int i,int v) {

选做题:两位十进制转换为二进制

#include<stdio.h> int main(void){ int i=0,n,a[32]; printf("请输入一个十进制整数:\n"); scanf("%d",&n); while(n>0) { a[i]=n%2; i=i+1; n=n/2; } printf("十进制整数转换为二进制数是:\n"); for(i--;i>=0;i--) printf("%d",a[i]); pri

选做题

有一个已经排好序的数组.现输入一个数,要求按原来的规律将它插入数组中. package test; public class test6 { public static void main(String[] args) { // TODO Auto-generated method stub int[] m = {0,1,3,4}; int[] m2 = new int[5]; int a = 2; for(int i =0; i< m.length; i++){ if(m[i] > a){

[SDOI2016]部分题选做

听说SDOI蛮简单的,但是SD蛮强的.. 之所以是选做,是因为自己某些知识水平还不到位,而且目前联赛在即,不好花时间去学sa啊之类的.. bzoj4517 数论题,我这种不会错排的数论白痴都能手推出来,这题应该谁都能写吧. #include<cstdio> #include<cstring> #include<algorithm> #define mo 1000000007 #define ll long long #define N 1000100 using nam

长对话做题规律

一.规律 1.题目与答案来源按照顺序分配,偶尔发生邻近错位: 2.对于大多数题目,都可以按照听啥选啥的原则,当所有选项都听到了,就按照3的方法: 3.做题三大规律:1)重复即所得 2)最后即所得 3)所听即所得 ,注意先后顺序 4.必须通过ABCD预判问题 5.注意个题目之间的逻辑和前后的一致性. 二.策略 1.历年真题反复听,注意对标志词的关注. 2.多记四级单词.

hdu--4432--好久没做题了.

很久没做题了...一想到要去 遥远的 牡丹江 我就------------- 这题 没什么好说的 就是个十进制的数转换成任意进制的数 就是要注意下 10进制以上的数 10是表示为A 11表示为B ......... 好 贴代码 继续做一两题. 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 vector<int>ve; 6 int num[110]; 7 int sum , n ,

做题细节

1. 如果题目是枚举的话,即最后化成十分简单的形式比较小, 可以直接将各种不同状态的结果运算过程写出来,但是这并不见得比写函数要快多少 而且比较容易出错,比如下标没有更改之类,这种错误比较烦人,因为你会查看算法, 但是算法本身并没有错误,所以如果复制粘贴的话,注意不同情况的不同点,如果自己 不够细心,最好写成函数的形式(注意判断边界),以防出错.//16:35 2004-4-17 2. 在编程之后检查的第一件事就是初始化, 你的初始化也许写在循环体之外,故只能AC一组测试数据,sample. /

bzoj5108 [CodePlus2017]可做题 位运算dp+离散

[CodePlus2017]可做题 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 87  Solved: 63[Submit][Status][Discuss] Description qmqmqm希望给sublinekelzrip出一道可做题.于是他想到了这么一道题目:给一个长度为n的非负整数序列ai,你需 要计算其异或前缀和bi,满足条件b1=a1,bi=bi?1 xor ai(i≥2).但是由于数据生成器出现了问题,他生成的序列a 的长度特