吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1273|回复: 15
收起左侧

[已解决] 怎样通过数字提示,输入答案检索正确与否?

[复制链接]
zhang1497 发表于 2021-11-23 21:59
本帖最后由 zhang1497 于 2021-11-25 19:30 编辑

先上图

最新在练习数字编码表,于是就想着能不能用python做一个程序。

经过指导,代码这样写了:
1。’新的问题来了,怎么实现一直出题,然后答对以后删题,继续出题。答错了不删题,继续下一题。直到字典里的元素为空时,提示闯关成功?
2。经过自己摸索,翻书,查百度。完成了。
3.还要再加上一个提前结束的指令,有什么没那么多时间。还没研究。下午再研究下。


[Python] 纯文本查看 复制代码
import random
A={"00":"望远镜","01":"小树","02":"铃儿","03":"凳子","04":"轿车","05":"手套","06":"手枪","07":"锄头","08":"溜冰鞋","09":"猫",
    "0":"呼啦圈","1":"蜡烛","2":"鹅","3":"耳朵","4":"帆船","5":"钩子","6":"勺子","7":"镰刀","8":"眼睛","9":"哨子","10":"棒球",
    "11":"梯子","12":"椅儿","13":"医生","14":"钥匙","15":"鹦鹉","16":"石榴","17":"仪器","18":"糖葫芦","19":"衣钩","20":"香烟",
    "21":"鳄鱼","22":"双胞胎","23":"和尚","24":"闹钟","25":"二胡","26":"河流","27":"耳机","28":"恶霸","29":"饿囚","30":"三轮车",
    "31":"鲨鱼","32":"扇儿","33":"星星","34":"三丝","35":"山虎","36":"山鹿","37":"山鸡","38":"妇女","39":"山丘","40":"司令",
    "41":"蜥蜴","42":"柿儿","43":"石山","44":"蛇","45":"师父","46":"饲料","47":"司机","48":"石板","49":"湿狗","50":"武林",
    "51":"工人","52":"鼓儿","53":"乌纱帽","54":"青年","55":"火车","56":"蜗牛","57":"武器","58":"尾巴","59":"蜈蚣","60":"榴莲",
    "61":"儿童","62":"牛儿","63":"流沙","64":"螺丝","65":"绿壶","66":"溜溜球","67":"绿漆","68":"喇叭","69":"太极","70":"麒麟",
    "71":"鸡翼","72":"企鹅","73":"花旗参","74":"骑士","75":"西服","76":"汽油","77":"机器","78":"青蛙","79":"气球","80":"巴黎",
    "81":"白蚁","82":"靶儿","83":"芭蕉扇","84":"巴士","85":"保姆","86":"八路","87":"白旗","88":"爸爸","89":"芭蕉","90":"酒瓶",
    "91":"球衣","92":"球儿","93":"旧伞","94":"首饰","95":"酒壶","96":"蝴蝶","97":"旧旗","98":"酒杯","99":"舅舅"}
while len(A) != 0:                              #建立一个判断,当列表不为空时,执行以下代码。
    qustion = random.choice(list(A.keys()))     #用字典A的key建立一个list(列表),通过random函数随机抽一个key,定义question变量
    answer = input('%s-' % (qustion))           #输入key键所对应的value值,例如给的是“00”这个键,那输入“望远镜”这个值。
    if answer == A[qustion]:                    #判断输入的这个值是不是对应了A列表里的key键。
        print("恭喜你,答对了")                    #如果对了,打印“恭喜你答对了”
        del A[qustion]                          #删除这个key,value。不断做对,列表A会越爱越少,直到变成空列表。
        continue                                #答对了题目,继续出题。
    else:                                       #如果输入的这个值不是key键所对应的。
        print('不好意思,你答错了,正确答案是',A[qustion])         #打印“不好意思,你错了”,并输入正确答案。不删题处理。
print("恭喜你过关了")                             #如果列表为空了,说明全部做对了,打印“恭喜过关”



4.晚上给它加上了分数和次数。接下来要再完善下多少分才算通关,否则失败。以及如何提前退出循环系统。注释如有不对还望提醒。
[Python] 纯文本查看 复制代码
import random
A={"00":"望远镜","01":"小树","02":"铃儿","03":"凳子","04":"轿车","05":"手套","06":"手枪","07":"锄头","08":"溜冰鞋","09":"猫",
    "0":"呼啦圈","1":"蜡烛","2":"鹅","3":"耳朵","4":"帆船","5":"钩子","6":"勺子","7":"镰刀","8":"眼睛","9":"哨子","10":"棒球",
    "11":"梯子","12":"椅儿","13":"医生","14":"钥匙","15":"鹦鹉","16":"石榴","17":"仪器","18":"糖葫芦","19":"衣钩","20":"香烟",
    "21":"鳄鱼","22":"双胞胎","23":"和尚","24":"闹钟","25":"二胡","26":"河流","27":"耳机","28":"恶霸","29":"饿囚","30":"三轮车",
    "31":"鲨鱼","32":"扇儿","33":"星星","34":"三丝","35":"山虎","36":"山鹿","37":"山鸡","38":"妇女","39":"山丘","40":"司令",
    "41":"蜥蜴","42":"柿儿","43":"石山","44":"蛇","45":"师父","46":"饲料","47":"司机","48":"石板","49":"湿狗","50":"武林",
    "51":"工人","52":"鼓儿","53":"乌纱帽","54":"青年","55":"火车","56":"蜗牛","57":"武器","58":"尾巴","59":"蜈蚣","60":"榴莲",
    "61":"儿童","62":"牛儿","63":"流沙","64":"螺丝","65":"绿壶","66":"溜溜球","67":"绿漆","68":"喇叭","69":"太极","70":"麒麟",
    "71":"鸡翼","72":"企鹅","73":"花旗参","74":"骑士","75":"西服","76":"汽油","77":"机器","78":"青蛙","79":"气球","80":"巴黎",
    "81":"白蚁","82":"靶儿","83":"芭蕉扇","84":"巴士","85":"保姆","86":"八路","87":"白旗","88":"爸爸","89":"芭蕉","90":"酒瓶",
    "91":"球衣","92":"球儿","93":"旧伞","94":"首饰","95":"酒壶","96":"蝴蝶","97":"旧旗","98":"酒杯","99":"舅舅"}
sum = 0                                         #定义一个变量初始值为0,收集做对题目数量
times = 20                                      #20次机会
while len(A) != 0 and times > 0 :               #建立一个判断,当列表不为空,而且输入次数不为0,执行以下代码。
    qustion = random.choice(list(A.keys()))     #用字典A的key建立一个list(列表),通过random函数随机抽一个key,定义question变量
    answer = input('%s--' % (qustion))          #输入key键所对应的value值,例如给的是“00”这个键,那输入“望远镜”这个值。
    times = times - 1                           #次数减1
    if answer == A[qustion]:                    #判断输入的这个值是不是对应了A列表里的key键。
        print("恭喜你,答对了")                    #如果对了,打印“恭喜你答对了”
        del A[qustion]                          #删除这个key,value。不再出现这个题,避免重复做题。
        sum = sum + 1                           #答对一题记一分
        continue                                #答对了题目,继续出题。
    else:                                       #如果输入的这个值不是key键所对应的。
        print('不好意思,你答错了,正确答案是',A[qustion])         #打印“不好意思,你错了”,并输入正确答案。不删题处理。
print("恭喜你过关了,做对了",sum,"道题,共计",sum*5,"分")           #20次机会用完了以后看看自己得了多少分


5,加了一个错误次数,以及错误时要多做5题。还有提前退出指令。
[Python] 纯文本查看 复制代码
import random
A={"00":"望远镜","01":"小树","02":"铃儿","03":"凳子","04":"轿车","05":"手套","06":"手枪","07":"锄头","08":"溜冰鞋","09":"猫",
    "0":"呼啦圈","1":"蜡烛","2":"鹅","3":"耳朵","4":"帆船","5":"钩子","6":"勺子","7":"镰刀","8":"眼睛","9":"哨子","10":"棒球",
    "11":"梯子","12":"椅儿","13":"医生","14":"钥匙","15":"鹦鹉","16":"石榴","17":"仪器","18":"糖葫芦","19":"衣钩","20":"香烟",
    "21":"鳄鱼","22":"双胞胎","23":"和尚","24":"闹钟","25":"二胡","26":"河流","27":"耳机","28":"恶霸","29":"饿囚","30":"三轮车",
    "31":"鲨鱼","32":"扇儿","33":"星星","34":"三丝","35":"山虎","36":"山鹿","37":"山鸡","38":"妇女","39":"山丘","40":"司令",
    "41":"蜥蜴","42":"柿儿","43":"石山","44":"蛇","45":"师父","46":"饲料","47":"司机","48":"石板","49":"湿狗","50":"武林",
    "51":"工人","52":"鼓儿","53":"乌纱帽","54":"青年","55":"火车","56":"蜗牛","57":"武器","58":"尾巴","59":"蜈蚣","60":"榴莲",
    "61":"儿童","62":"牛儿","63":"流沙","64":"螺丝","65":"绿壶","66":"溜溜球","67":"绿漆","68":"喇叭","69":"太极","70":"麒麟",
    "71":"鸡翼","72":"企鹅","73":"花旗参","74":"骑士","75":"西服","76":"汽油","77":"机器","78":"青蛙","79":"气球","80":"巴黎",
    "81":"白蚁","82":"靶儿","83":"芭蕉扇","84":"巴士","85":"保姆","86":"八路","87":"白旗","88":"爸爸","89":"芭蕉","90":"酒瓶",
    "91":"球衣","92":"球儿","93":"旧伞","94":"首饰","95":"酒壶","96":"蝴蝶","97":"旧旗","98":"酒杯","99":"舅舅"}
sum = 0                                         #定义一个变量初始值为0,收集做对题目数量
false = 0                                       #错误次数
times = 20                                      #20次机会
while times > 0 :                               #建立一个判断,当列表不为空,而且输入次数不为0,执行以下代码。
    question = random.choice(list(A.keys()))    #用字典A的key建立一个list(列表),通过random函数随机抽一个key,定义question变量
    answer = input('%s--' % (question))         #输入key键所对应的value值,例如给的是“00”这个键,那输入“望远镜”这个值。
    times = times - 1                           #次数减1
    if answer != 'x':                           #输入X提前退出练习
        if answer == A[question]:                    #判断输入的这个值是不是对应了A列表里的key键。
            #print("恭喜你,答对了")                    #如果对了,打印“恭喜你答对了”
            del A[question]                          #删除这个key,value。不再出现这个题,避免重复做题。
            sum = sum + 1                           #答对一题记一分
            continue                                #答对了题目,继续出题。
        else:                                       #如果输入的这个值不是key键所对应的。
            times = times + 5                       #错了再继续练习5次
            false = false + 1                       #错误次数累计加1
            print('不好意思,你答错了,正确答案是',question,'--',A[question])     #打印“不好意思,你错了”,并输入正确答案。不删题处理。
    else:
        print('已退出')                                #输入x就直接退出了
        break                                         #退出循环
print('----------测试结束----------\n正确:', sum, '\n错误:', false)   #正确错误情况
print('--------恭喜你挑战成功-------' if sum > 15 else '------挑战失败,再接再厉------')






免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
SFY110 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

qianshang666 发表于 2021-11-23 22:01
用列表一一对应不就行了
 楼主| zhang1497 发表于 2021-11-23 22:03
 楼主| zhang1497 发表于 2021-11-23 22:29
想到一个思路,建立一个序号列表,用来电脑出题的,然后再建立一个序号和答案为字符串的列表。这样用电脑输出的元素+自己输入的答案组成新的字符串,然后判断这个新的字符串是不是第二个列表里的元素,是就正确,不是就错误。我去试试。
qizhi45 发表于 2021-11-23 23:41
Python有个数据类型是字典即key-value对应
思路:先按照上面那个图构建字典,将数字作为key,文字作为value;
循环出题时先判断字典是不是为空,为空直接输出回答正确;
在范围中random一个key值访问其value,判断key对应的value存不存在,不存在则结束当前循环进入下一轮即再random一个;
然后跟你输入的答案对应,然后再判断你的对错逻辑,对的时候删除字典中的这个键值对。错的答案也结束当前循环。
yamika 发表于 2021-11-23 23:50
用列表存储一个key-value对,存储结构大致像这样[('0','呼啦圈‘),('1','蜡烛')。。。],00.01这些按字符串处理,然后顺序遍历列表即可
 楼主| zhang1497 发表于 2021-11-23 23:54
我是通过import random和字符串相加的原理来做的。
 楼主| zhang1497 发表于 2021-11-23 23:55
yamika 发表于 2021-11-23 23:50
用列表存储一个key-value对,存储结构大致像这样[('0','呼啦圈‘),('1','蜡烛')。。。],00.01这些按字符串 ...

我没有试过这类,能简单写个代码我学习下吗?
楼主你好萌 发表于 2021-11-24 08:54
这玩意,用字典很轻松就实现了
 楼主| zhang1497 发表于 2021-11-24 09:57
楼主你好萌 发表于 2021-11-24 08:54
这玩意,用字典很轻松就实现了

还没接触过字典,书才翻到几十页。哈哈。能编写给框架看看吗?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 19:24

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表