我的程序要求用户输入,但我想拒绝任何 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
最佳答案
您可以使用模运算符:
if Key % 26 == 0: # If Key / 26 returns no remainder
# Key is therefore divisible by 26
关于python - 如果输入是 x 的倍数,如何采取不同的行动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16290316/