在凯撒cypher在Python [英] Caesar cypher in Python
问题描述
请键入代码: 8 5 12 12 15
另一个例子:
请输入代码: 16 25 20 8 14 0 9 19 0 3 15 15 12
python很酷
字母表成这样的列表;
n = int(input(请输入代码:)
x = [ 'A', 'b', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', '0', 'p', 'q', 'R', 'S', 'T', 'U', 'v', 'W', 'X','Y ','z']
...然后再回来看,我也试过使用.replace()函数,像这样:
n = int (输入(请键入代码:)
n = n.replace('1','a')#all直到z然后循环它的方式
print(n)
等等,但是再一次,我不知道如何正确地执行此操作
任何帮助将不胜感激。谢谢。
使用 split()
numbers = input(请输入代码:).split()
#['16','25 ','20','8','14','0','9',',19','0','3','15','15' b
使用 for .. .. ..
数字中的数字:
print(x [int(num)])
如果您使用 0
作为空格
您必须在列表的开始位置添加空格
x = [ '','a','b','c',...]
x [0] ==''
I am new to python and I want to write a program that asks for a line of input (each number will be separated by a single space.) It would use a simple letter-number substitution cipher. Each letter will be appointed a number. So 1 = a, 2 = b and 3 = c until it reaches 26 = z. From there, however, the cipher would continue on so; 27 = a, 28 = b etc. 0's will be a space. The program will only use 0's and positive numbers. It would also print out the decryption of the message. For example:
Please type a code: 8 5 12 12 15
hello
and another example:
Please type a code: 16 25 20 8 14 0 9 19 0 3 15 15 12
python is cool
At the moment i have tried turning the alphabet into a list like this;
n = int(input("Please type a code: ")
x =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
...and then referring back to it later. However, im not exactly sure how this would work. I've also tried using the .replace() function. Like this:
n = int(input("Please type a code: ")
n = n.replace('1','a') #all the way until z and then loop it.
print(n)
and so and and so on. But again, i have no idea how to do this properly. Any help would be greatly appreciated. Thanks.
Use split()
numbers = input("Please type a code: ").split()
# ['16', '25', '20', '8', '14', '0', '9', ',19', '0', '3', '15', '15', '12']
Use for .. in ..
for num in numbers:
print( x[int(num)] )
If you use 0
as space
you have to add space
at the begginig of list
x = [' ', 'a', 'b', 'c', .... ]
now x[0] == ' '
这篇关于在凯撒cypher在Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!