2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

かなを数値に換算して和を求めるコード

2
Last updated at Posted at 2020-05-25

ひらがなを引数にとり、数値に換算して和を求めるコードを示します。
かな数値対応は、以下の表を参考にしています。romaji-hyou

kanacnt.py
# !/usr/bin/python3
import sys

kana = " あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやいゆえよらりるれろわゐうゑをん@@@@がぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽっゃゅょー"

a = sys.argv[1]
cnt = 0
for i in range(len(a)):
    if (a[i] in kana):
        cnt += kana.index(a[i])
print(cnt)

実行例

$ ./kanacnt.py ありす
56
$ ./kanacnt.py ねこ
34
$ ./kanacnt.py ひらがな
145
2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?