1

My program asks for an input from the user, but I want to reject any multiples of 26 (or if 0 is entered) and ask for the user to input again. I can't figure out how to do this; I'm guessing it's something to do with dividing the input by 26 and getting an integer.

The current code is:

  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 回答