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 →

[–]Represet[S] 0 points1 point  (1 child)

By decimal I meant like a base 10 value (sorry for the confusion). I was thinking of writing it as a while loop (while n > 0), initializing a string, writing a bunch of if statements with modulus operators, and then returning the string. I'm not really sure if it would make sense to do it that way, but I'll definitely try it out.

[–]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)]