Python實戰(zhàn)之IQ測試系統(tǒng)的實現(xiàn)
導語
智商測試
通常,智商測試測驗一個人在數(shù)字、空間、邏輯、詞匯、創(chuàng)造、記憶等方面的能力。
一般來說,50%的人口,即人口中的一半人屬于正常和平均智力水平(得分在90到109之間)。得分在110以上就屬于高智商者,即很聰明。
據(jù)稱,愛因斯坦智商得分160,屬于天才。?
今天在抖音上面刷到關(guān)于智商、情商、愛情啥等好多測試的小程序,麻了麻了。
所以小編從上面獲得了靈感,哈哈哈,你想的沒錯,就是這樣,給大家上線一款這種測試IQ的小系統(tǒng),快來測一測你的智商又多高叭~

一、運行環(huán)境
小編使用的環(huán)境:Python3、Pycharm社區(qū)版、其他都是內(nèi)置模塊 你安裝 好python環(huán)境就可以了。
二、資料素材
準備好相應的測試題目,下面是30題目,答案也要準備好哦~還有測試的分數(shù)標準嘞都準備好撒

三、代碼展示
import os
import random
import datetime
def read_file(path, file_name):
"""
讀取文件函數(shù)
:param path: 路徑
:param file_name: 文件名稱
:return: 文件內(nèi)容
"""
# 這里的/ 也可以換成\\
with open(path + "/" + file_name, "r", encoding="utf8") as file:
content = file.read() # 因為文件內(nèi)容比較少 所以直接使用read方法一次性全部讀取
return content
if __name__ == '__main__':
print("=======================IQ智力測試(限時版)=======================")
print("-" * 55)
print("說明: 測試時間: 30分鐘,測試題數(shù): 30")
now = datetime.datetime.now() # 獲取當前時間
delay_time = datetime.timedelta(minutes=30)
stop_time = now + delay_time
print("測試結(jié)束時間為: ", stop_time.strftime("%Y-%m-%d %H:%M:%S"))
len_que = len(os.listdir("./que"))
score = 0 # 用來統(tǒng)計得分
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("請輸入正確答案前面的數(shù)字編號: ").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("答題超時,將結(jié)束測試!")
break
else:
print(f"剩余答題時間:{left}分鐘")
i += 1
print(f"你的IQ測試成績?yōu)? {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)木子測試

到此這篇關(guān)于Python實戰(zhàn)之IQ測試系統(tǒng)的實現(xiàn)的文章就介紹到這了,更多相關(guān)Python IQ測試系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python實現(xiàn)TCP/IP協(xié)議下的端口轉(zhuǎn)發(fā)及重定向示例
這篇文章主要介紹了Python實現(xiàn)TCP/IP協(xié)議下的端口轉(zhuǎn)發(fā)及重定向示例,以一個webpy站點在本機的兩個端口雙向通信下演示,需要的朋友可以參考下2016-06-06
keras 實現(xiàn)輕量級網(wǎng)絡ShuffleNet教程
這篇文章主要介紹了keras 實現(xiàn)輕量級網(wǎng)絡ShuffleNet教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06

