I’m trying to print dictionary item value of a dictionary but my item is also an another user input variable. How can I print the selected value with f-string?
JavaScript
x
7
1
option = ''
2
languages = {'1':'Learn Python', '2':'Learn Java', '3':'Learn C++', '4':'Learn PHP', '5':'Quit'}
3
option = input('Please choose an option between 1 and 5')
4
5
# Following part is not working!!!
6
print(f'Youve selected {languages["{option}"]}')
7
Advertisement
Answer
JavaScript
1
3
1
# Following part is working!!!
2
print(f'Youve selected {languages[option]}')
3