I am trying to use a user's input to display specific information from a dictionary. Everything works fine besides the last print command. I enter 'pd' in hopes of it turning into print(pd['name']) like the line above it but I get an error.
Here is my code.
pd = {
'name': 'project destroyer',
'retail': '$200',
'website': 'https://projectdestroyer.com/'
}
dashe = {
'name': 'dashe',
'retail': '$200',
'website': 'https://dashe.com/'
}
favbot = input('What is your favorite bot? ')
print(pd['name'])
print(favbot['name'])
Here is my output and error message.
What is your favorite bot? pd
project destroyer
Traceback (most recent call last):
File "/Library/Phxn/Code/botfnder/bot_dict.py", line 18, in <module>
print(favbot['name'])
TypeError: string indices must be integers
What is the difference in me manually entering pd['name'] as opposed to favbot = pd ... favbot['name']? I have thoroughly searched this error and just can't seem to understand how to fix it. Any help would be appreciated.
favbotis a string inputted by the user sofavbot['name']doesn't make sense.'name'infavbot['name'].