-2

I want to write a program that makes 0 into A, 1 into B, 2 into C, and so on, and I've tried just doing this:

def problem(number):
    return chr(number) - chr(0)

But no matter what my input is, I always get A.

martineau
  • 119,623
  • 25
  • 170
  • 301
abner_218
  • 1
  • 1
  • 1
    Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation, as suggested when you created this account. [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your MCVE code and accurately describe the problem. We should be able to paste your posted code into a text file and reproduce the problem you described. Your posted code fails when it tries to subtract two strings (one character each). – Prune Oct 10 '18 at 17:22
  • `alphanum = ''.join(chr(n) for n in range(48, 123) if chr(n).isalnum()); table = str.maketrans(alphanum, alphanum[10:] + alphanum[:10]);print('12 Cats'.translate(table))` gives `BC Mk32`. – Steven Rumbalski Oct 10 '18 at 17:45
  • You should return chr(number - ord('0') + ord('A')) You need a character, so the last step is always a chr() call – user2341726 Oct 14 '18 at 03:40

1 Answers1

0
import string

def problem(number):
    if number > len(string.ascii_uppercase):
        return None
    return string.ascii_uppercase[number]
it's-yer-boy-chet
  • 1,917
  • 2
  • 12
  • 21