Hello Everyone!

I am new to Python, this is my second project. I am trying to make a program that will take a users input and then output the words into the format where A = 1, B = 2, C =3 ... and so on. I want to start this basic just to get my feet wet before I plunge in. Though I'm having a few problems, I think right now it is a problem with the input:

test = raw_input(">")
test = test2.replace('a', '1')
print test2

Help would be most appreciated!
Austin Jackson

Actually As I Think There Is A Problem With Compiler So Just Reconfig The Compiler Dic And You Will Get The Correct Results!

Not quite sure what you want, but maybe this will help ...

word = raw_input("Enter a word: ")
for c in word:
    c = c.upper()
    print c, "=", ord(c) - 64

"""
my output for instance -->
A = 1
B = 2
S = 19
O = 15
L = 12
U = 21
T = 20
E = 5
"""

Actually Ord evalution is pretty much ISD you will need to reclarify the isd checkpoint for python in the ord section.
ok!

Hey inkcoder,

There is a slight problem with the code you posted. You posted:

test = raw_input(">")
test = test2.replace('a', '1')
print test2

I believe you wanted:

test = raw_input(">")
test2 = test.replace('a', '1')
print test2

I think that should produce the desired response.

Thanks Vegaseat your reply was very helpful but a little bit off and I'm having difficulties editing your code.
What I really wanted was for the output to be seamless example:
TEST = 20.5.19.20

Thanks Everyone!
Austin

encode = lambda txt: ".".join([str(ord(letter)-96) for letter in txt if ord(letter) in range(97,123)])

decode = lambda txt: "".join([chr(int(char)+96) for char in txt.split(".") if int(char) in range(1, 27)])

Output >>>

>>> encode('this is a message!!!') # anything not lowercase a-z gets silently ignored
'20.8.9.19.9.19.1.13.5.19.19.1.7.5' 

>>> decode('20.8.9.19.9.19.1.13.5.19.19.1.7.5')
'thisisamessage' # spaces and '!' are gone

pseudo:

new_string = ""
for each character in string:
   check the character is lowercase a-z
   covert character to ascii code and minus 96 
   convert the number back into a string and add it onto the end of new_string

return new_string

Hope that helps,
a1eio

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.