My program takes a user input such as:
>>> x = input()
>>> 1
>>> print x
>>> one
my actual code:
>>> import string
>>> numbers = ['0','1','2','3','4','5','6','7','8','9']
>>> wordNumbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
>>> myDict = dict(zip(numbers, wordNumbers))
>>> myVar = (raw_input("Enter a number to be tranlated: "))
>>> for translate in myVar.split():
>>> print(myDict[translate])
The problem is I need the user to input 123 and for my program to output one two three, but it doesn’t for some reason.
I’m thinking that if I add spaces with some syntax between 123 like 1 2 3 it would work.
You simply need to use:
Instead of:
Iterating over a string gives you its characters one by one, which is what you need.
If you do want to convert
'123'to'1 2 3'(which isn’t needed here because you don’t need to usesplit), you can use: