-1

I've done a bit of looking around, and couldn't find an answer to my question, so I'd like some help. In my program, the user inputs a letter, say 'G', and I need the program to print the value stored in the variable G. Such as:

G = 'Hello!'

variable = input('Enter a letter').upper()

I then want the program to print 'Hello!' when the user enters the letter G, but I'm unsure how to do this. I did come across the exec() function (which may be useful?), but I don't understand it enough to do anything with it.

Any help would be appreciated.

George Willcox
  • 645
  • 11
  • 29

1 Answers1

0

Search a little bit next time but I give you a solution :

Use locals()

a = 'foo'
locals()['a']
'foo'
Benjamin
  • 2,938
  • 3
  • 21
  • 43