栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

用Python实现一个猜密码的程序

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用Python实现一个猜密码的程序

完整代码:`

在这里插入代码片
```import random
print("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --密码猜猜猜-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --")
print("正确密码由四个互不相同的大写字母组成,猜猜看呐")
letterList = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
passwordList = []
count = 0
gjr = ""
while True:
    index = random.randint(0,len(letterList)-1)
    letter = letterList[index]
    passwordList.append(letterList[index])
    letterList.pop(index)
    count += 1
    if count == 4:
        break
while True:    
    user = input("请输入密码:")
    userList = list(user)
    if len(userList) == 4:
        posCorrect = 0
        if passwordList[0] == userList[0]:
            posCorrect += 1
        if passwordList[1] == userList[1]:
            posCorrect += 1
        if passwordList[2] == userList[2]:
            posCorrect += 1
        if passwordList[3] == userList[3]:
            posCorrect += 1
        pos_right = ("位置对了:" + str(posCorrect))
        letterCorrect = 0
        if userList[0] in passwordList:
            letterCorrect += 1
        if userList[1] in passwordList:
            letterCorrect += 1
        if userList[2] in passwordList:
            letterCorrect += 1
        if userList[3] in passwordList:
            letterCorrect += 1
        letter_right = ("字母对了:" + str(letterCorrect))
        if userList == passwordList:
            print("猜对了,你真棒")
            break
        else:
            print(pos_right + letter_right)
    else:
        print("别乱输")


`
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/980332.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号