Python需要帮助,如何使一个crypter在字母表上移位+1

时间:2015-04-11 23:12:29

标签: python

我正在制作一个菜单,其中的所有内容都是完美的,但我现在需要的是在最终用户输入一个句子时,在某种意义上制作一个管章,他/她输入的所有字母将按字母顺序向上移动+1例如:

Input: The Dog Jumped
Expected output: uif!eph!kvnqfe

我编码的内容:

def crypts():
print()
print("You said the following:")
time.sleep(1)
sentenc = input("Please enter your sentence: ")
print(sentenc)
print()
print("Your crypted sentence is:")
senten = crp(sentenc)
time.sleep(1)
print(senten)
again()

然后这就是我需要帮助解决的问题

def crp(c):
dont know what to type here what so ever, i am gone blank sadly:z

1 个答案:

答案 0 :(得分:0)

您可以在ord值中添加一个,然后使用chr再次转换为字符:

s="The Dog Jumped"

In [14]: enc = "".join([chr(ord(c)+1) for c in s])   
In [15]: enc
Out[15]: 'Uif!Eph!Kvnqfe'    
In [16]: dec = "".join([chr(ord(c)-1) for c in enc])    
In [17]: dec
Out[17]: 'The Dog Jumped'