我正在开发一个解密Caesar密码的程序。当我运行程序时,没有输出。提前谢谢!
这是我的代码
def test():
value = input("Value here!")
with open ("cipher.*txt") as f:
nice_strings = []
for line in f:
line = line.strip()
nice_str_chars = []
for char in line:
int_of_char = ord(char)
int_of_char += value
nice_char = chr(int_of_char)
nice_str_chars.append(nice_char)
nice_str = ''.join(nice_str_chars)
nice_strings.append(nice_str)
print (line, '=>', nice_str, '\n')
return nice_strings
答案 0 :(得分:0)
我突然想到几个问题:
在您提供的代码中永远不会调用此函数。
文件名
似乎有问题需要将输入值转换为整数,以便数学运算...
def test():
### convert the input to an integer
value = int(input("Value here!"))
### presuming you want 'cipher.txt' versus 'cipher.*txt'
with open ("cipher.txt") as f:
nice_strings = []
for line in f:
line = line.strip()
nice_str_chars = []
for char in line:
int_of_char = ord(char)
int_of_char += value
nice_char = chr(int_of_char)
nice_str_chars.append(nice_char)
nice_str = ''.join(nice_str_chars)
nice_strings.append(nice_str)
print (line, '=>', nice_str, '\n')
return nice_strings
### don't forget to call your function:
test()