I was trying to finish an assignment until I reached this small issue.
My dilemma is: My output is printed correctly, but how do I get the key # and its respective output to be printed together neatly?
Example:
key 1: ABCDEB
key 2: EFGFHI
etc
My Code:
def main():
# hardcode
phrase = raw_input ("Enter the phrase you would like to decode: ")
# 1-26 alphabets (+3: A->D)
# A starts at 65, and we want the ordinals to be from 0-25
# everything must be in uppercase
phrase = phrase.upper()
# this makes up a list of the words in the phrase
splitWords = phrase.split()
output = ""
for key in range(0,26):
# this function will split each word from the phrase
for ch in splitWords:
# split the words furthur into letters
for x in ch:
number = ((ord(x)-65) + key) % 26
letter = (chr(number+65))
# update accumulator variable
output = output + letter
# add a space after the word
output = output + " "
print "Key", key, ":", output
main()
print "Key " + key + ": " + output + "\n", notice the spaces and newline added.