python 實現九型人格測試小程式

來源:互聯網
上載者:User

標籤:auto   with   images   help   show   shadow   rip   程式   img   

用python實現九型人格測試,並把測試結果繪製成餅圖,實現代碼如下:

# @Description: 九型人格import xlrd, matplotlib.pyplot as pltdata = xlrd.open_workbook(r‘E:\python_script\nine.xlsx‘)table = data.sheets()[0]checkout = []#儲存題號labs = [] #儲存九種性格sizes = [] #儲存大小explode=[0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05]#每塊之間的間隙with open(‘ninp.txt‘, encoding=‘utf-8‘) as f:    f.seek(0)    rule = eval(f.read())    f.close()for i in range(table.nrows):    if table.row_values(i)[2] == 1:  # 如果選中的是1 則把題號存入checkout        checkout.append(int(table.row_values(i)[0]))for i in checkout:    for j in rule:        if i in rule[j][‘QNO‘]:  # 如果題號在規則中,則size +1            rule[j][‘size‘] += 1for x in rule:    labs.append(x)    sizes.append(rule[x][‘size‘])plt.figure(figsize=(12,6))plt.title("My Test Result \n")colors=[‘lightgreen‘,‘gold‘,‘lightskyblue‘,‘lightcoral‘,‘red‘,‘blue‘,‘yellow‘,‘darkgreen‘,‘purple‘]plt.pie(sizes,explode=explode,labels=labs,colors=colors,                                labeldistance=1.1,autopct=‘%3.1f%%‘,shadow = False,                                startangle=90,pctdistance=0.6)plt.axis(‘equal‘)plt.legend()plt.show()

運行結果如下:


ninp.txt裡儲存的規則字典格式如下:

{"Perfect":{‘QNO‘:[2,14,55,57,60,63,73,81,87,91,97,102,104,106],‘size‘:0},"Helping":{‘QNO‘:[6,8,22,30,69,71,79,82,85,86,89,90],‘size‘:0},"Achievement":{‘QNO‘:[20,33,38,59,65,67,70,72,74,77,80,93],‘size‘:0},"Ego":{‘QNO‘:[7,13,17,52,53,54,56,58,61,64,100,105],‘size‘:0},"Observation":{‘QNO‘:[3,19,23,32,42,43,47,48,51,83,88,99,101],‘size‘:0},"Loyal":{‘QNO‘:[9,10,26,29,31,35,37,45,46,68,75],‘size‘:0},"Hedonism":{‘QNO‘:[4,16,18,21,28,49,78,92,103],‘size‘:0},"Leading":{‘QNO‘:[5,11,24,27,40,44,50,66,76,84,95,96],‘size‘:0},"Peace":{‘QNO‘:[1,12,15,25,34,36,39,41,62,94,98,107,108],‘size‘:0}}

 

nine.xlsx檔案題目及測試結果內容如下:

 


python 實現九型人格測試小程式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.