Python实战之IQ测试系统的实现

Tina ·
更新时间:2024-09-20
· 548 次阅读

目录

导语

一、运行环境

二、资料素材

三、代码展示

四、效果展示

1)智商测试限时版本

​2)木子测试

导语

智商测试

通常,智商测试测验一个人在数字、空间、逻辑、词汇、创造、记忆等方面的能力。

一般来说,50%的人口,即人口中的一半人属于正常和平均智力水平(得分在90到109之间)。得分在110以上就属于高智商者,即很聪明。

据称,爱因斯坦智商得分160,属于天才。​

今天在抖音上面刷到关于智商、情商、爱情啥等好多测试的小程序,麻了麻了。

所以小编从上面获得了灵感,哈哈哈,你想的没错,就是这样,给大家上线一款这种测试IQ的小系统,快来测一测你的智商又多高叭~

一、运行环境

小编使用的环境:Python3、Pycharm社区版、其他都是内置模块 你安装 好python环境就可以了。

二、资料素材

准备好相应的测试题目,下面是30题目,答案也要准备好哦~还有测试的分数标准嘞都准备好撒

三、代码展示 import os import random import datetime def read_file(path, file_name): """ 读取文件函数 :param path: 路径 :param file_name: 文件名称 :return: 文件内容 """ # 这里的/ 也可以换成\\ with open(path + "/" + file_name, "r", encoding="utf8") as file: content = file.read() # 因为文件内容比较少 所以直接使用read方法一次性全部读取 return content if __name__ == '__main__': print("=======================IQ智力测试(限时版)=======================") print("-" * 55) print("说明: 测试时间: 30分钟,测试题数: 30") now = datetime.datetime.now() # 获取当前时间 delay_time = datetime.timedelta(minutes=30) stop_time = now + delay_time print("测试结束时间为: ", stop_time.strftime("%Y-%m-%d %H:%M:%S")) len_que = len(os.listdir("./que")) score = 0 # 用来统计得分 msg = ["智商1级: 白痴", "智商1级: 白痴", "智商1级: 白痴", "智商1级: 白痴", "智商1级: 白痴", "智商2级: 智障", "智商3级: 智弱", "智商4级: 临界", "智商5级: 凡人", "智商6级: 聪慧", "智商7级: 人才", "智商8级: 精英", "智商9级: 天才", "智商9级: 天才", "智商9级: 天才", "智商9级: 天才", "智商9级: 天才", "智商9级: 天才", "智商9级: 天才"] msg2 = ["白痴", "智障", "智弱", "临界", "凡人", "聪慧", "人才", "精英", "天才"] num_list = list(range(1, len_que + 1)) i = 1 while len(num_list) > 0: num = random.choice(num_list) num_list.remove(num) print(f"\n第 {i} 题: \n" + read_file("./que", "que" + str(num) + ".txt")) # 用户输入答案 user_ans = input("请输入正确答案前面的数字编号: ").strip() # 读取正确答案 right_ans = read_file("./ans", "ans" + str(num) + ".txt").strip() if user_ans == right_ans: # 判断用户输入答案与正确一致 score += 6 # 答案一致加6分 now = datetime.datetime.now() left = int((stop_time - now).seconds / 60) if left <= 0: print("答题超时,将结束测试!") break else: print(f"剩余答题时间:{left}分钟") i += 1 print(f"你的IQ测试成绩为: {score} {msg[int(score / 10)]}") # 将成绩和等级写入文件 with open("iq.txt", "a", encoding="utf8") as file: file.write(str(score) + "," + msg[int(score / 10)].split(":")[1].strip() + "\n") # 读取文件中的测试成绩及等级 score_list = [] # 用来存储所有的成绩 level_list = [] # 用来存储所有的等级 if os.path.exists("iq.txt"): with open("iq.txt", "r", encoding="gbk") as file: while True: line_content = file.readline().strip() if line_content == "": break else: score_list.append(int(line_content.split(",")[0].strip())) level_list.append(line_content.split(",")[1].strip()) # 对成绩进行排序 score_list.sort(reverse=True) print(f"目前您在所有测试的成绩中排名第{score_list.index(score) + 1}名," f"超过了{len(score_list) - (score_list.index(score) + 1)}名选手") print("智商测试分析图: ") for item in msg2: print(item, int(level_list.count(item)) * chr(9632), level_list.count(item)) 四、效果展示 1)智商测试限时版本

​2)木子测试

到此这篇关于Python实战之IQ测试系统的实现的文章就介绍到这了,更多相关Python IQ测试系统内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!



Python实战 iq 系统 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号