输入/输出如下: 第1组: “abcde”“128” 预期产量/实际产量 “abcde”/“abcde”
第二组: “abcde”“100” 预期产量/实际产量 “EFGHI”/“«¬®¯"
第三组: “你好,世界”“3” 预期产量/实际产量 “Khoor#Zruog”/“Khoor#Zruog”
设置1&;3正确返回,但2不正确。我认为这与我试图使用的字符集有关,但我不知道如何修复它
plainText = input("Enter text to encrypt: ")
distance = int(input("Enter number of offset: "))
code = ""
for ch in plainText:
distance %= 56
ordValue = ord(ch)
cipherValue = ordValue + distance
if cipherValue > ord('z'):
cipherValue = ord('a') + distance -(ord('z') - ordValue + 1)
code = code + chr(cipherValue)
print("distance= ",distance)
print(code)
我可能不太清楚你想要什么,但我知道你包装得不对。这就是你想做的吗(它确实适用于您提供的示例。)
相关问题 更多 >
编程相关推荐