Skip to content

Instantly share code, notes, and snippets.

@GaryLee
Created December 16, 2015 16:03
Show Gist options
  • Select an option

  • Save GaryLee/258954f5b4e252f5c083 to your computer and use it in GitHub Desktop.

Select an option

Save GaryLee/258954f5b4e252f5c083 to your computer and use it in GitHub Desktop.
拼音輸入法練習
#!python
# coding: utf-8
tbl = [
{'symbol': u'ㄅ', 'basic': 'b', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄆ', 'basic': 'p', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄇ', 'basic': 'm', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄈ', 'basic': 'f', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄉ', 'basic': 'd', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄊ', 'basic': 't', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄋ', 'basic': 'n', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄌ', 'basic': 'l', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄍ', 'basic': 'g', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄎ', 'basic': 'k', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄏ', 'basic': 'h', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄐ', 'basic': 'j', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄑ', 'basic': 'q', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄒ', 'basic': 'x', 'combine': None, 'category': 'sound'},
{'symbol': u'ㄓ', 'basic': 'zhi', 'combine': 'zh', 'category': 'sound'},
{'symbol': u'ㄔ', 'basic': 'chi', 'combine': 'ch', 'category': 'sound'},
{'symbol': u'ㄕ', 'basic': 'shi', 'combine': 'sh', 'category': 'sound'},
{'symbol': u'ㄖ', 'basic': 'ri', 'combine': 'r', 'category': 'sound'},
{'symbol': u'ㄗ', 'basic': 'zi', 'combine': 'z', 'category': 'sound'},
{'symbol': u'ㄘ', 'basic': 'ci', 'combine': 'c', 'category': 'sound'},
{'symbol': u'ㄙ', 'basic': 'si', 'combine': 's', 'category': 'sound'},
{'symbol': u'ㄚ', 'basic': 'a', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄛ', 'basic': 'o', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄜ', 'basic': 'e', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄝ', 'basic': 'e', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄞ', 'basic': 'ai', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄟ', 'basic': 'ei', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄠ', 'basic': 'ao', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄡ', 'basic': 'ou', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄢ', 'basic': 'an', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄣ', 'basic': 'en', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄤ', 'basic': 'ang', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄥ', 'basic': 'eng', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄦ', 'basic': 'er', 'combine': None, 'category': 'rhyme'},
{'symbol': u'ㄧ', 'basic': 'yi', 'combine': 'i', 'category': 'rhyme'},
{'symbol': u'ㄧㄚ', 'basic': 'ya', 'combine': 'ia', 'category': 'rhyme'},
{'symbol': u'ㄧㄝ', 'basic': 'ye', 'combine': 'ie', 'category': 'rhyme'},
{'symbol': u'ㄧㄠ', 'basic': 'yao', 'combine': 'iao', 'category': 'rhyme'},
{'symbol': u'ㄧㄡ', 'basic': 'you', 'combine': 'iu', 'category': 'rhyme'},
{'symbol': u'ㄧㄢ', 'basic': 'yan', 'combine': 'ian', 'category': 'rhyme'},
{'symbol': u'ㄧㄣ', 'basic': 'yin', 'combine': 'in', 'category': 'rhyme'},
{'symbol': u'ㄧㄤ', 'basic': 'yang', 'combine': 'iang', 'category': 'rhyme'},
{'symbol': u'ㄧㄥ', 'basic': 'ying', 'combine': 'ing', 'category': 'rhyme'},
{'symbol': u'ㄨ', 'basic': 'wu', 'combine': 'u', 'category': 'rhyme'},
{'symbol': u'ㄨㄚ', 'basic': 'wa', 'combine': 'ua', 'category': 'rhyme'},
{'symbol': u'ㄨㄛ', 'basic': 'wo', 'combine': 'uo', 'category': 'rhyme'},
{'symbol': u'ㄨㄞ', 'basic': 'wai', 'combine': 'uai', 'category': 'rhyme'},
{'symbol': u'ㄨㄟ', 'basic': 'wei', 'combine': 'ui', 'category': 'rhyme'},
{'symbol': u'ㄨㄢ', 'basic': 'wan', 'combine': 'uan', 'category': 'rhyme'},
{'symbol': u'ㄨㄣ', 'basic': 'wen', 'combine': 'un', 'category': 'rhyme'},
{'symbol': u'ㄨㄤ', 'basic': 'wang', 'combine': 'uang', 'category': 'rhyme'},
{'symbol': u'ㄨㄥ', 'basic': 'weng', 'combine': 'ong', 'category': 'rhyme'},
{'symbol': u'ㄩ', 'basic': 'yu', 'combine': 'u', 'category': 'rhyme'},
{'symbol': u'ㄩㄝ', 'basic': 'yue', 'combine': 'ue', 'category': 'rhyme'},
{'symbol': u'ㄩㄢ', 'basic': 'yuan', 'combine': 'uan', 'category': 'rhyme'},
{'symbol': u'ㄩㄣ', 'basic': 'yun', 'combine': 'un', 'category': 'rhyme'},
{'symbol': u'ㄩㄥ', 'basic': 'yong', 'combine': 'iong', 'category': 'rhyme'}]
def main():
import re
for x in tbl:
while True:
if not x['combine']:
print x['symbol'], '(basic):',
else:
print x['symbol'], '(basic, combine):',
ans = raw_input().strip()
ans = re.split('[, ]+', ans)
error_message = ""
if not x['combine']:
if ans[0] != x['basic']:
error_message = 'WRONG: %s' % x['basic']
else:
if not (len(ans) >= 2 and ans[0] == x['basic'] and ans[1] == x['combine']):
error_message = 'WRONG: %s %s' % (x['basic'], x['combine'])
if not error_message:
print '\t\tPASSED!!'
break
else:
print '\t\t', error_message
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment