I want to convert given phone number into respective letters
0 -> 'a'
1 -> 'b'
2 -> 'c' etc.
E.g. the number 210344222 should get converted to the string 'cbadeeccc'. I understand my return is wrong at the end which is where I am stuck, so can you please explain how I would instead return the letter conversions.
def phone(x):
"""
>>> phone(22)
'cc'
>>> phone(1403)
'bead'
"""
result = ""
x = str(x)
for ch in x:
if x == 0:
print('a')
elif x == 1:
print('b')
elif x == 3:
print('c')
return result
Aucun commentaire:
Enregistrer un commentaire