I'm very new to programming so forgive me if anything doesn't make sense or if I word things incorrectly. I have a question about using tuples as dictionary keys.
First, I have the user input a number,
num = input("Enter a number here: ")
Then, I turn this number value into a tuple:
numTup = tuple(num)
Next, I create a dictionary connecting numerical keys to word values:
numWords = {'1': "One", '2': "Two", '3': "Three", '4': "Four", '5': "Five", '6': "Six", '7': "Seven", '8': "Eight", '9': "Nine"}
And finally, I want it to print the dictionary values that correspond to the keys in the tuple. I'm pretty sure this is where I'm getting it wrong.
print(numWords[numTup])
Essentially what I'm trying to do with this program is have it print each user inputted digit as a word, ie. 456 would turn into "four five six".
The full (incorrect) script:
num = input("Enter a number here: ")
numTup = tuple(num)
numWords = {'1': "One", '2': "Two", '3': "Three", '4': "Four", '5': "Five", '6': "Six", '7': "Seven", '8': "Eight", '9': "Nine"}
print(numWords[numTup])
inputis also a string. You can use it as a key directly, the way you've set it up, without converting it to anything.('3', '1', '0'), your lookup is looking for that exact key, not for the keys3,1,0. You need to iterate over the the values of the tuple and use those values (which are strings) as keys. Since your dictionary has strings for keys.for digit in inputstring:will start just such a loop. then in the loop you can just printnumWords[digit]