【python】——第四次作业

 

import hashlib

UI = """
************
1.注册
2.登录
************
"""

salt = '1835929550zzsqq'

# print(UI)
# select = int(input('请输入正确的序号:'))


def register():
    account = input('请输入账号:')
    password = input('请输入密码:')
    password = encrypt(password)
    with open("password.txt", "a") as f:
        f.writelines(account + ":" + password + "\n")
        f.close()


def login():
    account = input('请输入账号:')
    password = input('请输入密码:')
    password = encrypt(password)
    dc = from_password()
    if account in dc:
        if dc[account] == password:
            print("登录成功")
        else:
            print("密码错误")
    else:
        print("账号不存在")



def from_password():
    ls = []
    with open("password.txt", "r") as f:
        while True:
            s = f.readline().replace("\n","")
            ls.append(s)
            if s == "":
                break
    dc = dict()
    for iteam in ls:
        ac_pwd = iteam.split(":")
        if len(ac_pwd) >= 2:
            dc[ac_pwd[0]] = ac_pwd[1]
    return dc


def encrypt(pwd: str):
    md5 = hashlib.md5(pwd.encode())
    md5.update(salt.encode())
    return md5.hexdigest()

while True:
    print(UI)
    select = int(input('请输入正确的序号:'))
    if select == 1:
        register()
    elif select == 2:
        login()
import math


class Shape:
    def __init__(self, center_x, center_y):
        self._center_x = center_x
        self._center_y = center_y


class Rectangle(Shape):
    def __init__(self, center_x, center_y, w, h):
        super().__init__(center_x, center_y)
        self.width = w
        self.height = h

    def is_in(self, x, y):
        if self._center_x + self.width / 2 > x > self._center_x - self.width / 2 \
                and self._center_y + self.height / 2 > y > self._center_y - self.height / 2:
            return True
        else:
            return False


class Circle(Shape):
    def __init__(self, center_x, center_y, r):
        super().__init__(center_x, center_y)
        self.r = r

    def is_in(self, x, y):
        if math.sqrt((x - self._center_x) ** 2 + (y - self._center_y) ** 2) <= self.r:
            return True
        else:
            return False

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一张不够花!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值