這篇文章目是透過程式取得「驗證問題」裡的選項,再用程式來自動把選項用來回答問題。
厲害的人都是使用 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’]
上面是一般的「小菜」,但出問題的人又不是呆瓜,他們也不想被機器人拿來猜,所以他們進化問題的格式:
基本入門的題型:

說明:上面的答案是 3C

說明:上面是 2/15 的問題,答案是 jjx。
附註:2/14 的問題:以下哪個「不是」正確的林俊傑與其他藝人合唱的歌曲組合?(選項為歌名/合作藝人 ,請以半形輸入法作答選項,大小寫需要一模一樣,範例:jju) 選項: (jja)小酒窩/A-Sa蔡卓妍 (jjb)被風吹過的夏天/金莎 (jjc)友人說/張懷秋 (jjd)全面開戰/五月天阿信 (jje)小說/阿杜
有時候會問開放性的問題,題目裡沒有選項:


請以半形數字輸入您所購買節目的演出日期,如演出日期為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.
回答指定文字:

王力宏:


被要求連括號都輸入:

《2019 LOVELYZ CONCERT in TAIPEI》

RAVI 3rd REAL-LIVE [R.OOK BOOK] IN TAIPEI



變動長度問題:

同時問2個問題:
下面問題的答案是 C2。
Dara是橙色,朴春綠色,CL金色以及敏智是紫色。根據她們不同喜好所訂製的麥克風,都代表著她們獨一無二的特色。

開放性的問題:

這個要猜也行,猜26次一定猜的到。團名是:GARNiDELiA,唯一小寫是 i
相關文章:
[Python] RegEx
https://stackoverflow.max-everyday.com/2019/04/python-regex/
[Python] 如何判斷字串中的語言
https://stackoverflow.max-everyday.com/2019/04/python-regex-detect-language/
[Python] 结巴中文分词
https://stackoverflow.max-everyday.com/2019/05/jieba/