我的程序要求用户输入,但我想拒绝任何26的倍数(或输入0)并要求用户再次输入.我无法弄清楚如何做到这一点; 我猜这是将输入除以26得到一个整数.
目前的代码是:
ValidInput = False
while ValidInput == False:
try:
Key = int(input('Enter the amount that shifts the plaintext alphabet to the ciphertext alphabet: '))
except:
print("Sorry, that isn't an integer. ")
else:
ValidInput = True
return Key
Run Code Online (Sandbox Code Playgroud)
您可以使用模运算符:
if Key % 26 == 0: # If Key / 26 returns no remainder
# Key is therefore divisible by 26
Run Code Online (Sandbox Code Playgroud)