[Tutor] Print random letters
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Dec 22 01:08:33 CET 2005
> I want to print out random letters from A - Z. I know how to do this
> with numbers, but don't know with letters.
Hi Johan,
There's a "mapping" between numbers and letters through the ord() and
chr() built-in functions. ord() takes in a character and returns a
number, and chr() takes in a number and returns a character.
For example:
######
>>> ord('a')
97
>>> chr(97 + 25)
'z'
######
So yet another approach might be to take what you already know --- getting
random numbers --- and just translating those numbers to characters.
Best of wishes to you!
More information about the Tutor
mailing list