這篇文章目是透過程式取得「驗證問題」裡的選項,再用程式來自動把選項用來回答問題。
厲害的人都是使用 Regular Expression. 讓我們來看看範例:
請問下列哪張專輯為___出道專輯?(1A)飛(2B)礫(3C)樂(請以半形輸入法作答,大小寫需要一模一樣,範例:1A)
要取得上面句子裡的選項,可以使用:
re.findall('([\w]+)', text))
這樣子就結束了,但很多人看不懂或不知道如何使用,參考看看更多的範例
# split all string
>>> source = "Hello World max everyday"
>>> re.findall('[\w]+', source)
['Hello', 'World', 'max', 'everyday']
input = """"<person>John</person>went to<location>London</location>"""
import re
print(re.findall("<person>(.*?)</person>", input)) print(re.findall("<location>(.*?)</location>", input))
上面執行結果是 [‘John’] 和 [‘London’]
上面是一般的「小菜」,但出問題的人又不是呆瓜,他們也不想被機器人拿來猜,所以他們進化問題的格式:
基本入門的題型:
![](http://max-everyday.com/wp-content/uploads/2018/12/Screenshot-2018-12-14-00.48.03-1024x240.jpg)
說明:上面的答案是 3C
![](http://max-everyday.com/wp-content/uploads/2018/12/Screen-Shot-2018-12-20-at-20.09.45-1024x252.jpg)
說明:上面是 2/15 的問題,答案是 jjx。
附註:2/14 的問題:以下哪個「不是」正確的林俊傑與其他藝人合唱的歌曲組合?(選項為歌名/合作藝人 ,請以半形輸入法作答選項,大小寫需要一模一樣,範例:jju) 選項: (jja)小酒窩/A-Sa蔡卓妍 (jjb)被風吹過的夏天/金莎 (jjc)友人說/張懷秋 (jjd)全面開戰/五月天阿信 (jje)小說/阿杜
有時候會問開放性的問題,題目裡沒有選項:
![](http://max-everyday.com/wp-content/uploads/2018/12/Screenshot-2018-12-14-01.07.39-1024x207.jpg)
![](http://max-everyday.com/wp-content/uploads/2019/03/Screen-Shot-2019-03-21-at-18.51.29-1024x196.jpg)
請以半形數字輸入您所購買節目的演出日期,如演出日期為2019/03/30,請輸入20190330。Please enter the date of the show you purchased in halfwidth form.For example: the date of the show is 2019/03/30,please enter 20190330.
回答指定文字:
![](http://max-everyday.com/wp-content/uploads/2018/12/Screenshot-2018-12-16-22.58.13-1024x206.jpg)
王力宏:
![](http://max-everyday.com/wp-content/uploads/2019/01/D4-2060-1024x194.jpg)
![](http://max-everyday.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-12-at-14.48.21.jpg)
被要求連括號都輸入:
![](http://max-everyday.com/wp-content/uploads/2019/02/Screen-Shot-2019-02-17-at-10.05.07-1024x246.jpg)
《2019 LOVELYZ CONCERT in TAIPEI》
![](http://max-everyday.com/wp-content/uploads/2019/03/Screen-Shot-2019-03-06-at-15.24.39-1024x222.jpg)
RAVI 3rd REAL-LIVE [R.OOK BOOK] IN TAIPEI
![](http://max-everyday.com/wp-content/uploads/2019/03/Screen-Shot-2019-03-11-at-00.23.20.jpg)
![](http://max-everyday.com/wp-content/uploads/2019/03/Screen-Shot-2019-03-23-at-12.32.51-1024x249.jpg)
![](http://max-everyday.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-14-at-01.53.22.jpg)
變動長度問題:
![](https://max-everyday.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-13-at-22.33.47-1024x219.jpg)
同時問2個問題:
下面問題的答案是 C2。
Dara是橙色,朴春綠色,CL金色以及敏智是紫色。根據她們不同喜好所訂製的麥克風,都代表著她們獨一無二的特色。
![](https://max-everyday.com/wp-content/uploads/2019/05/Screen-Shot-2019-05-27-at-00.53.59-1024x238.jpg)
開放性的問題:
![](http://max-everyday.com/wp-content/uploads/2019/04/Screen-Shot-2019-04-18-at-08.20.21.jpg)
這個要猜也行,猜26次一定猜的到。團名是:GARNiDELiA,唯一小寫是 i
相關文章:
[Python] RegEx
http://stackoverflow.max-everyday.com/2019/04/python-regex/
[Python] 如何判斷字串中的語言
http://stackoverflow.max-everyday.com/2019/04/python-regex-detect-language/
[Python] 结巴中文分词
https://stackoverflow.max-everyday.com/2019/05/jieba/