>>> r = input('??')
??ab
>>> ''.join(m[c] for c in r)
'000'
>>> r = input('??')
??ac
>>> ''.join(m[c] for c in r)
'0000'
>>> r = input('??')
??abc
>>> ''.join(m[c] for c in r)
'000000'
>>>
Make a dictionary mapping characters to the symbol you want.
>>> m = {'a':'0','b':'00', 'c':'000'}
Then use it along with a user's input
>>> r = input('??')
??ab
>>> ''.join(m[c] for c in r)
'000'
>>> r = input('??')
??ac
>>> ''.join(m[c] for c in r)
'0000'
>>> r = input('??')
??abc
>>> ''.join(m[c] for c in r)
'000000'
>>>
发布评论
评论(2)
将字典映射为您想要的符号。
然后将其与用户的输入一起使用
Make a dictionary mapping characters to the symbol you want.
Then use it along with a user's input
这是一个简单的程序,可以执行您的要求:
Here is a simple program that does what you are asking for: