【发布时间】:2016-02-28 13:19:15
【问题描述】:
我一直在玩 Python,遇到了麻省理工学院的一项任务,即创建编码消息(Julius Cesar 代码,例如,您将消息中的 ABCD 字母更改为 CDEF)。这是我想出的:
Phrase = input('Type message to encrypt: ')
shiftValue = int(input('Enter shift value: '))
listPhrase = list(Phrase)
listLenght = len(listPhrase)
ascii = []
for ch in listPhrase:
ascii.append(ord(ch))
print (ascii)
asciiCoded = []
for i in ascii:
asciiCoded.append(i+shiftValue)
print (asciiCoded)
phraseCoded = []
for i in asciiCoded:
phraseCoded.append(chr(i))
print (phraseCoded)
stringCoded = ''.join(phraseCoded)
print (stringCoded)
代码有效,但我必须实现不移动消息中空格和特殊符号的 ascii 值。
所以我的想法是在 range(65,90) 和 range(97,122) 范围内的列表中选择值并更改它们,而我不更改任何其他值。但是我该怎么做呢?
【问题讨论】:
-
你可以使用
isalpha()方法stackoverflow.com/questions/15558392/…
标签: python python-3.x