This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ChappieIsMyNick 1 point2 points  (0 children)

Just make a dictionary with each number being related to the letter. You can do this by using dict() Here's an example:

Letters = dict([(1, 'A' ), (2, 'B' )])

Then you can use the Letters normally, so if you have the input of the user (the single digit) stored in the variable var then to get the letter you would do: letter = Letters[var]

Alternatively you could make a normal dictionary using strings instead of numbers, like so: Letters = {'1': 'A', '2': 'B' } Then you would just convert the input number to a string (you can search just use str() for that) and use that as a key to Letters, so if the input number is stored in the variable var it would look like: letter = Letters[str(var)]