在遇到这个小问题之前,我一直在努力完成一项任务。
我的困境是:我的输出打印正确,但是如何让键 # 及其各自的输出整齐地打印在一起?
例子:
关键1:ABCDEB
关键2:EFGFHI
ETC
我的代码:
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()