2019-06-19:文字列I am a boyは、次のルールに従って数値に変換してください.abc–2, def–3, ghi–4, jkl–5, mno–6, pqrs–7, tuv–8 wxyz–9
890 ワード
def lettersChangeDatas(new_s):
s_list=new_s.split()
print(s_list)
new_s=''
for words in s_list:
for letter in words:
if letter.lower() in "abc":
new_s+=str(2)
elif letter.lower() in "def":
new_s+=str(3)
elif letter.lower() in "ghi":
new_s+=str(4)
elif letter.lower() in "jkl":
new_s+=str(5)
elif letter.lower() in "mno":
new_s+=str(6)
elif letter.lower() in "pqrs":
new_s += str(7)
elif letter.lower() in "tuv":
new_s += str(8)
elif letter.lower() in "wxyz":
new_s += str(9)
return new_s
print(lettersChangeDatas("I am a boy"))