def main():
key = []
mess=input('Write Text: ')
for ch in mess:
x = ord(ch)
x = x-3
x = chr(x)
key.append(x)
print("Your code message is: ",key)
outFile = open("Encryptedmessage.txt","w")
print(key, file=outFile)
main()到目前为止,我已经写了这个a,它工作得很好,但我的问题是输出
Write Text: the
Your code message is: ['q', 'e', 'b']我想知道如何去掉标点符号,这样输出结果就会是
Write Text: the
Your code message is: qeb发布于 2015-09-08 06:04:18
key是一个列表。您可以使用join(list)将列表中的元素连接在一起:
print("Your code message is: ", "".join(key))
str.join(iterable)
返回一个字符串,它是可迭代迭代器中字符串的串联。元素之间的分隔符是提供此方法的字符串。
来源:https://docs.python.org/2.7/library/stdtypes.html?#str.join
您不希望列表元素之间有任何分隔符,因此请使用空字符串""作为分隔符。
发布于 2015-09-08 06:05:57
可能会替换掉
key=[]使用
key=""并替换
key.append(x)使用
key=key+xhttps://stackoverflow.com/questions/32446537
复制相似问题