商品管理系统_蓝桥杯Python创意编程省赛的第六题参考答案

"""
   蓝桥杯Python创意编程省赛的第六题
   商品管理系统省赛参考答案
"""

from random import *

def listgoods(goods):
    """列出所有商品"""
    for g in goods:
        print(g)
        
def readfile(txtfile):
    """读取文本文件"""
    f = open(txtfile)
    c = f.read()
    f.close()
    return c
    
def login(valid_file):
    """从valid_file中读取文件验证"""
    # 生成验证码
    digits = '0123456789'
    s = [choice(digits) for _ in range(6)]
    s = "".join(s)        # s是自动生成的验证码字符串
    # 打开验证文件
    c = readfile(valid_file)
    if not "," in c : return False

    userpass = c.split(',')
    username = userpass[0]
    password = userpass[1]
    print("你的登录验证码为",s)
    u = input("请输入用户名:")
    p = input("请输入密码:")
    v = input("请输入验证码:")
    return u == username and p == password and v == s

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在Uncategorized分类目录。将固定链接加入收藏夹。