1

私のプログラムはユーザーからの入力を求めますが、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
4

1 に答える 1

8

モジュロ演算子を使用できます。

if Key % 26 == 0:  # If Key / 26 returns no remainder
    # Key is therefore divisible by 26
于 2013-04-30T00:22:47.333 に答える