I am making a Caesar cipher in Python. I had created a function to return the message the user would want to encrypt. I then wanted to do the same for cipher key. I wanted the function to only return the key if it was between 1 and 26 because that is the size of the alphabet. It works but when I purposefully enter a number bigger than 26 THEN enter a number that is in between 1 and 26; it apparently returns 'None'. This is my first time using recursion.
def getKey():
print("Enter the key you want to use to decrypt/encrypt the message")
key = int(input()) # key input
while True:
if key >= 1 and key <= 26: #checking if key is in between range
return key #giving back the key
else: # this should run whenever the input is invalid
print ("The key must be inbetween 1 and 26")
break # to stop the loop
getKey() # Recursion, to restart the function
key = getKey()
print(key) # this prints 'None'
What happened to the key? Where did it go!?