数值错误:chr()参数不在0x110000的范围内。

7

我正在编写一个解码程序,但是遇到了以下错误:

ValueError: chr()参数不在范围内(0x110000)

当我输入需要解码的字符串时发生上述错误。输入的字符串为:

[2ea^W_`^k2eiWSd2fZSf2[2S_2gb2fa2`a2YaaV@

当前的代码如下所示:
# String manipulation
# This program accepts a string and an integer
# then decodes the number of lines by a know decryption key

# Initialize the program and necessary variable
print("This progam can decode an encrypted by a known encryption key")
string=""
decoded_message=""
coded_message=""

# Prompting the used for input using a for loop to accept multiple lines
coded_message=input("What is the line to be decoded?")

# Using a for loop, the messges will be decrypted character
# at at time to its ASCII value then decrypted and converted
# back to text
for string in coded_message:
    converted_text=ord(string)
    decryption=(chr(converted_text-18))
    decoded_message+=decryption
# Output the decoded message
print("Your decrypted message is:",decoded_message)

我确定我错过了一些简单的东西,但任何帮助都将是极好的。

1个回答

2
也许当您从原始ASCII值中减去18时,它会超出范围,即小于0。

原来这就是问题所在。我们要测试的消息中有一个不应该存在的空格。 - Wyatt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接