Beschränken der Benutzereingabe auf einen Bereich in Python
Im folgenden Code werden Sie aufgefordert, einen Verschiebungswert einzugeben. Mein Problem ist, dass ich die Eingabe auf 1 bis 26 begrenzen möchte.
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 finds the character by its ASCII code
Wie mache ich das einfach?