i want to convert a int to a string which is in words i.e one,two,three
l = int(input('Phone : '))
k = {'1':'one','2':'two','3':'three'}
for ch in k :
k.get('ch')
print(ch)
i tried to get the output but i just got the int itself
CodePudding user response:
k = {'1':'one','2':'two','3':'three'}
for ch in k.values() :
#k.get('ch')
print(ch)
Use loop through the values of the dictionary elements.
Output will be :
one
two
three
CodePudding user response:
I understood what you wanted but you explained it really hard. I think this is the code you want.
number = input('Phone : ')
dict = {'1':'one','2':'two','3':'three')
for n in number:
x = dict.get(n)
print(x)
CodePudding user response:
number = input('Phone : ')
k = {'1':'one','2':'two','3':'three'}
for n in number:
print(k.get(n))
CodePudding user response:
l = int(input('Phone : '))
numlist = {'1':'one','2':'two','3':'three'}
for key in numlist:
if l==int(key):
print(numlist.get(key))
Is this what you wanted?