---
title: "了解wiki的统计问卷"
author: "caicono"
date: "2010-01-15T21:36:00Z"
tags: []
slug: "wiki"
draft: false
lastmod: "2010-01-15T21:36:00Z"
id: 609058
url: "https://caicono.iteye.com/blog/609058"
---

待续，尚未写完。

 

wiki问卷：

问题1：您了解wiki (百科)吗？

　

选项

A. 没听说过

B. 没有使用过，仅仅浏览过

C. 不仅使用，而且贡献过词条

D. 对wiki的技术原理、实现等比较清楚

您的选择

　

问题2：某个网站具有站内wiki功能，或者本身就是某一个领域的专业百科网站，您对这种网站什么态度？

　选项

A. 有兴趣

B. 无兴趣

C. 无所谓，不影响我

您的选择

　

问题3. 如果贡献词条，则您愿意贡献词条的原因是：

 

A. 兴趣

B. 成就感

C. 让专业知识得到积累和沉淀

D. 可结识一些志同道合的朋友

E. 即使了解也不想贡献，太麻烦

F. 其它

您的选择

　(可多选)

问题4. 现有wiki网站（如维基百科，baidu，soso百科等）的功能如何？

　选项

A. 很好，完全满足要求

B. 多媒体信息（音视频）更丰富些

C. 词条更专业些

D. 表述更简洁一些，比如通俗易懂些

E. 通过手机更方便快捷地访问

F. 其它

您的选择

　(可多选)

 

如果您对此问卷有任何疑惑或者建议，可以写在下方，谢谢。

　

　

实例数据：

  学历 行业 1 2 3 4 1 0 b b a b 2 0 a c f f 3 2 b c abc bc 4 1 b a bcd bd 5 1 b c e cd 6 1 a a c bd 7 2 b a cd b 8 2 b a abcd bc 9 0 b c ac c 10 1 b a e bc 11 2 b a ac bd 12 1 b c ab abc 13 2 b a c c 14 2 b a a bc 15 2 b a ac bc 16 2 c a ac cf 17 2 b a ac cd 18 2 a a d e 19 2 b a abc bc 20 1 d a bcd d 21 2 a a d e 22 1 b c a d

统计程序，前面两道题分别有3个和2个选项，单选。后面两道题均有6个选项，多选。

统计每道题选择a，b，c，d的百分比。很简单的需求。实现如下(发现python中没有自加操作符)：

 

```

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1 def calc():
 2 
 3     file = open('C:\\wiki-query2.txt','r')
 4     content = file.read()
 5     import re
 6     entries = re.split('\n+',content)
 7     for entry in entries:
 8         if(len(entry) == 0 ):
 9             break
10         #print(entry)
11          words = (re.split('\t',entry))
12         #words = (str(words)).strip()
13         #print(words[0]+","+words[4])
14         checkSingleChoice(words[4],answer1)
15         checkSingleChoice(words[5],answer2)
16         checkMuliChoice(words[6],answer3)
17         checkMuliChoice(words[7],answer4)
18 
19     file.close()
20     print(answer1)
21     print(answer2)
22     print(answer3)
23     print(answer4)
24     print('the results are:')
25     calPercent(answer1,1)
26     calPercent(answer2,2)
27     calPercent(answer3,3)
28     calPercent(answer4,4)
29 
30 
31 
32 def checkSingleChoice(item, answer):
33         if item == 'a':
34             answer[0] = answer[0]+1
35         elif item =='b':
36             answer[1]= answer[1]+1
37         elif item =='c':
38             answer[2]= answer[2]+1
39         else:
40             answer[3]= answer[3]+1
41 
42 def checkMuliChoice(item, answer):
43     if 'a' in item:
44         answer[0] = answer[0]+1
45     if 'b' in item:
46         answer[1]= answer[1]+1
47     if 'c' in item:
48         answer[2]= answer[2]+1
49     if 'd' in item:
50         answer[3]= answer[3]+1
51     if 'e' in item:
52         answer[4]= answer[4]+1
53     if 'f' in item:
54         answer[5]= answer[5]+1
55 
56 
57 
```

 

最终结果：

 

```

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
[4, 16, 1, 1]
[15, 1, 6, 0]
[12, 6, 13, 6, 2, 1]
[1, 12, 12, 7, 2, 2]
the results are:
Q[1]:
choice[a] :18.18%, choice[b] :72.73%, choice[c] :4.55%, choice[b] :4.55%, 
Q[2]:
choice[a] :68.18%, choice[b] :4.55%, choice[c] :27.27%, choice[b] :0.00%, 
Q[3]:
choice[a] :30.00%, choice[b] :15.00%, choice[c] :32.50%, choice[b] :15.00%, choice[e] :5.00%, choice[f] :2.50%, 
Q[4]:
choice[a] :2.78%, choice[b] :33.33%, choice[c] :33.33%, choice[b] :19.44%, choice[e] :5.56%, choice[f] :5.56%, 
```

其中，在统计函数的显示百分比方法中，要设置print结果显示的小数位数，花了些时间找方法，结果：

print(':%.2f' %(p)+'%',end=', ')，f表示小数点为是，g表示有效数字位数，e为科学技计数法。

 

```

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1 def testDouble():
2     f=1/3  
3     print('%.3e %.3f %.3g' % (f,f,f))
4 
```

 

```

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1 def calPercent(answer,num):
 2     count = len(answer)
 3     sum = 0
 4     percents =[]
 5     for item in answer:
 6         sum += item
 7     for item in answer:
 8         percent = ((item *100)/ sum) 
 9         percents.append(percent)
10 
11     choice = {1:'a',2:'b',3:'c',4:'b',5:'e',6:'f'}
12     print('Q[%s]:'%num)
13     i = 1
14     for p in percents:
15         print('choice['+choice[i]+']',end=' ')
16         i+=1
17         print(':%.2f' %(p)+'%',end=', ')
18     print()
```

 

 

  \[4, 16, 1, 1] \[15, 1, 6, 0] \[12, 6, 13, 6, 2, 1] \[1, 12, 12, 7, 2, 2] the results are: Q\[1]: choice\[a] :18.18%, choice\[b] :72.73%, choice\[c] :4.55%, choice\[b] :4.55%,  Q\[2]: choice\[a] :68.18%, choice\[b] :4.55%, choice\[c] :27.27%, choice\[b] :0.00%,  Q\[3]: choice\[a] :30.00%, choice\[b] :15.00%, choice\[c] :32.50%, choice\[b] :15.00%, choice\[e] :5.00%, choice\[f] :2.50%,