小编Kra*_*ubb的帖子

将用户输入限制在 Python 中的某个范围内

在下面的代码中,您会看到它要求一个“移位”值。我的问题是我想将输入限制为 1 到 26。

    For char in sentence:
            if char in validLetters or char in space: #checks for
                newString += char                     #useable characters
        shift = input("Please enter your shift (1 - 26) : ")#choose a shift
        resulta = []
        for ch in newString:
            x = ord(ch)      #determines placement in ASCII code
            x = x+shift      #applies the shift from the Cipher
            resulta.append(chr(x if 97 <= x <= 122 else 96+x%122) if ch != \
            ' ' else ch) # This line …
Run Code Online (Sandbox Code Playgroud)

python range

4
推荐指数
2
解决办法
6万
查看次数

Python Caesar Cipher保留空间

我需要帮助保持空间.我有caesar密码功能,但我希望它保留空间,无法弄清楚如何做到这一点.

sentence = raw_input("Please enter a sentence : ").lower()
newString = ''
validLetters = "abcdefghijklmnopqrstuvwxyz"
space = [ ]
for char in sentence:
    if char in validLetters or char in space:
        newString += char
        shift = input("Please enter your shift : ")
        resulta = []
for ch in newString:
    x = ord(ch)
    x = x + shift
    resulta.append(chr(x if 97 <= x <= 122 else 96 + x % 122))
print sentence
print("")
print("Your encryption is :")
print("")
print ''.join(resulta) …
Run Code Online (Sandbox Code Playgroud)

python encryption

0
推荐指数
1
解决办法
3532
查看次数

标签 统计

python ×2

encryption ×1

range ×1