我一直在玩Python和对面麻省理工学院,这一任务是创建编码消息(凯撒代码中,例如,你的消息改变ABCD字母CDEF)来了。这是我想出了:选择从列表中选择特定int类型,并改变它们
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值。
所以我的想法是在范围(65,90)和量程(97122)范围内选择列表值和改变他们,而我不会改变任何人。但我该怎么做?
你可以使用'isalpha()'方法http://stackoverflow.com/questions/15558392/how-to-check-if-character-in-string-is-a-word-character-python – RinaLiu